Skip to content

Commit

Permalink
Refactor Puma::Cluster::WorkerHandle#ping!
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuay03 committed Mar 16, 2024
1 parent 58c31b2 commit 6ec6b68
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/puma/cluster/worker_handle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ def term?
@term
end

STATUS_PATTERN = /{ "backlog":(?<backlog>\d*), "running":(?<running>\d*), "pool_capacity":(?<pool_capacity>\d*), "max_threads": (?<max_threads>\d*), "requests_count": (?<requests_count>\d*) }/
private_constant :STATUS_PATTERN

def ping!(status)
@last_checkin = Time.now
captures = status.match(/{ "backlog":(?<backlog>\d*), "running":(?<running>\d*), "pool_capacity":(?<pool_capacity>\d*), "max_threads": (?<max_threads>\d*), "requests_count": (?<requests_count>\d*) }/)
@last_status = captures.names.inject({}) do |hash, key|
hash[key.to_sym] = captures[key].to_i
hash
end
@last_status = status.match(STATUS_PATTERN).named_captures.map { |c_name, c| [c_name.to_sym, c.to_i] }.to_h
end

# @see Puma::Cluster#check_workers
Expand Down

0 comments on commit 6ec6b68

Please sign in to comment.