Skip to content

Commit

Permalink
Fix guard clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
robertomiranda committed Aug 15, 2024
1 parent 1581a4b commit 54f74be
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/promenade/pitchfork/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def initialize

raindrops_stats = Raindrops::Stats.new

@active_workers = raindrops_stats.active_workers
@queued_requests = raindrops_stats.queued_requests
@active_workers = raindrops_stats.active_workers || 0
@queued_requests = raindrops_stats.queued_requests || 0
end

def instrument
Expand All @@ -47,16 +47,13 @@ def self.instrument
attr_reader :workers_count, :live_workers_count, :active_workers, :queued_requests

def capacity
return 0 if live_workers_count.nil? || active_workers.nil?
return 0 if live_workers_count&.zero?
return 0 if active_workers&.zero?
return 0 if live_workers_count.nil? || live_workers_count.zero?

live_workers_count - active_workers
end

def busy_percent
return 100 if live_workers_count.zero?
return 100 if active_workers&.zero?
return 0 if live_workers_count.zero?

(active_workers.to_f / live_workers_count) * 100
end
Expand Down

0 comments on commit 54f74be

Please sign in to comment.