Module: AnyCable::Rack::RPCRunner
- Extended by:
- Logging
- Defined in:
- lib/anycable/rack/rpc_runner.rb
Overview
Runs AnyCable CLI in a separate process
Constant Summary
Constants included from Logging
Class Attribute Summary collapse
-
.pid ⇒ Object
Returns the value of attribute pid.
-
.running ⇒ Object
Returns the value of attribute running.
Class Method Summary collapse
- .run(root_dir:, command_args: [], rpc_host: "[::]:50051", env: {}) ⇒ Object
- .running? ⇒ Boolean
- .stop ⇒ Object
Class Attribute Details
.pid ⇒ Object
Returns the value of attribute pid.
15 16 17 |
# File 'lib/anycable/rack/rpc_runner.rb', line 15 def pid @pid end |
.running ⇒ Object
Returns the value of attribute running.
15 16 17 |
# File 'lib/anycable/rack/rpc_runner.rb', line 15 def running @running end |
Class Method Details
.run(root_dir:, command_args: [], rpc_host: "[::]:50051", env: {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/anycable/rack/rpc_runner.rb', line 17 def run(root_dir:, command_args: [], rpc_host: "[::]:50051", env: {}) return if @running command_args << "--rpc-host=\"#{rpc_host}\"" command = "bundle exec anycable #{command_args.join(' ')}" log(:info, "Running AnyCable (from #{root_dir}): #{command}") out = AnyCable.config.debug? ? STDOUT : IO::NULL @pid = Dir.chdir(root_dir) do Process.spawn( env, command, out: out, err: out ) end log(:debug) { "AnyCable PID: #{pid}" } @running = true at_exit { stop } end |
.running? ⇒ Boolean
54 55 56 |
# File 'lib/anycable/rack/rpc_runner.rb', line 54 def running? running == true end |
.stop ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/anycable/rack/rpc_runner.rb', line 44 def stop return unless running log(:debug) { "Terminate PID: #{pid}" } Process.kill("SIGKILL", pid) @running = false end |