Class: HttpLoader::Harness::ProcessManager
- Inherits:
-
Object
- Object
- HttpLoader::Harness::ProcessManager
- Extended by:
- T::Sig
- Defined in:
- lib/http_loader/harness/process_manager.rb
Overview
Manages child process lifecycles natively and checks status dynamically.
Instance Attribute Summary collapse
-
#client_pid ⇒ Object
readonly
Returns the value of attribute client_pid.
-
#server_pid ⇒ Object
readonly
Returns the value of attribute server_pid.
Instance Method Summary collapse
- #cleanup ⇒ Object
-
#initialize(config) ⇒ ProcessManager
constructor
A new instance of ProcessManager.
- #missing_process? ⇒ Boolean
- #spawn_processes ⇒ Object
Constructor Details
#initialize(config) ⇒ ProcessManager
Returns a new instance of ProcessManager.
16 17 18 19 20 21 |
# File 'lib/http_loader/harness/process_manager.rb', line 16 def initialize(config) @config = config @server_pid = T.let(nil, T.nilable(Integer)) @client_pid = T.let(nil, T.nilable(Integer)) @log_dir = T.let(File.('../../../logs', __dir__), String) end |
Instance Attribute Details
#client_pid ⇒ Object (readonly)
Returns the value of attribute client_pid.
13 14 15 |
# File 'lib/http_loader/harness/process_manager.rb', line 13 def client_pid @client_pid end |
#server_pid ⇒ Object (readonly)
Returns the value of attribute server_pid.
13 14 15 |
# File 'lib/http_loader/harness/process_manager.rb', line 13 def server_pid @server_pid end |
Instance Method Details
#cleanup ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/http_loader/harness/process_manager.rb', line 31 def cleanup begin Process.kill('INT', T.must(@server_pid)) if @server_pid rescue StandardError; nil end begin Process.kill('INT', T.must(@client_pid)) if @client_pid rescue StandardError; nil end end |
#missing_process? ⇒ Boolean
43 44 45 46 47 48 |
# File 'lib/http_loader/harness/process_manager.rb', line 43 def missing_process? return true if @client_pid && dead?(@client_pid) return true if @server_pid && dead?(@server_pid) false end |
#spawn_processes ⇒ Object
24 25 26 27 28 |
# File 'lib/http_loader/harness/process_manager.rb', line 24 def spawn_processes FileUtils.mkdir_p(@log_dir) spawn_server unless @config.target_urls.any? spawn_client end |