Class: ActiveJob::Temporal::HealthCheckServer
- Inherits:
-
Object
- Object
- ActiveJob::Temporal::HealthCheckServer
- Includes:
- HttpLineReader
- Defined in:
- lib/activejob/temporal/health_check_server.rb
Constant Summary collapse
- DEFAULT_BIND_ADDRESS =
"127.0.0.1"- READ_TIMEOUT_SECONDS =
1- CONNECTION_WORKERS =
4- CONNECTION_QUEUE_SIZE =
16
Instance Attribute Summary collapse
-
#bind_address ⇒ Object
readonly
Returns the value of attribute bind_address.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(port:, state:, bind_address: DEFAULT_BIND_ADDRESS, allow_public_bind: false) ⇒ HealthCheckServer
constructor
A new instance of HealthCheckServer.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(port:, state:, bind_address: DEFAULT_BIND_ADDRESS, allow_public_bind: false) ⇒ HealthCheckServer
Returns a new instance of HealthCheckServer.
23 24 25 26 27 28 29 30 |
# File 'lib/activejob/temporal/health_check_server.rb', line 23 def initialize(port:, state:, bind_address: DEFAULT_BIND_ADDRESS, allow_public_bind: false) @requested_port = Integer(port) @bind_address = bind_address @allow_public_bind = allow_public_bind @state = state @running = false @mutex = Mutex.new end |
Instance Attribute Details
#bind_address ⇒ Object (readonly)
Returns the value of attribute bind_address.
21 22 23 |
# File 'lib/activejob/temporal/health_check_server.rb', line 21 def bind_address @bind_address end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
21 22 23 |
# File 'lib/activejob/temporal/health_check_server.rb', line 21 def port @port end |
Instance Method Details
#running? ⇒ Boolean
73 74 75 |
# File 'lib/activejob/temporal/health_check_server.rb', line 73 def running? @mutex.synchronize { @running } end |
#start ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/activejob/temporal/health_check_server.rb', line 32 def start @mutex.synchronize do return self if @running BindPolicy.validate!( endpoint: "health check", bind_address: bind_address, allow_public_bind: @allow_public_bind ) @server = TCPServer.new(bind_address, @requested_port) @port = @server.addr[1] @connection_pool = ConnectionWorkerPool.new( size: CONNECTION_WORKERS, queue_size: CONNECTION_QUEUE_SIZE, name: "activejob-temporal-health" ) { |client| serve_client(client) }.start @running = true @thread = Thread.new { run } end self end |
#stop ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/activejob/temporal/health_check_server.rb', line 53 def stop server = nil thread = nil connection_pool = nil @mutex.synchronize do server = @server thread = @thread connection_pool = @connection_pool @server = nil @thread = nil @connection_pool = nil @running = false end server&.close connection_pool&.stop(timeout: 2) thread&.join(2) end |