-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose
Pitchfork::Info.workers_count
and .live_workers_count
This allow health check endpoints to consider the state of the whole Pitchfork instance. e.g. you may want to fail the health check if more than X% of the workers aren't live.
- Loading branch information
Showing
6 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'pitchfork/shared_memory' | ||
|
||
module Pitchfork | ||
module Info | ||
@workers_count = 0 | ||
|
||
class << self | ||
attr_accessor :workers_count | ||
|
||
def live_workers_count | ||
now = Pitchfork.time_now(true) | ||
(0...workers_count).count do |nr| | ||
SharedMemory.worker_deadline(nr).value > now | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use Rack::ContentLength | ||
use Rack::ContentType, "text/plain" | ||
run lambda { |env| | ||
info = { | ||
workers_count: Pitchfork::Info.workers_count, | ||
live_workers_count: Pitchfork::Info.live_workers_count, | ||
} | ||
|
||
[ 200, {}, [ info.inspect ] ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'integration_test_helper' | ||
|
||
class InfoTest < Pitchfork::IntegrationTest | ||
def test_after_request_complete | ||
addr, port = unused_port | ||
|
||
pid = spawn_server(app: File.join(ROOT, "test/integration/info.ru"), config: <<~CONFIG) | ||
listen "#{addr}:#{port}" | ||
worker_processes 2 | ||
CONFIG | ||
|
||
assert_healthy("http://#{addr}:#{port}") | ||
|
||
response = http_get("http://#{addr}:#{port}/") | ||
assert_equal "{:workers_count=>2, :live_workers_count=>2}", response.body | ||
|
||
assert_clean_shutdown(pid) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters