Class: Spring::ApplicationManager
- Inherits:
-
Object
- Object
- Spring::ApplicationManager
- Defined in:
- lib/spring-jruby/impl/fork/application_manager.rb,
lib/spring-jruby/impl/pool/application_manager.rb
Defined Under Namespace
Classes: Worker, WorkerPool
Instance Attribute Summary collapse
-
#child ⇒ Object
readonly
Returns the value of attribute child.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(app_env) ⇒ ApplicationManager
constructor
A new instance of ApplicationManager.
- #restart ⇒ Object
-
#run(client) ⇒ Object
Returns the name of the screen running the command, or nil if the application process died.
- #start ⇒ Object
- #stop ⇒ Object
-
#synchronize ⇒ Object
We’re not using @mutex.synchronize to avoid the weird “<internal:prelude>:10” line which messes with backtraces in e.g.
Constructor Details
#initialize(app_env) ⇒ ApplicationManager
Returns a new instance of ApplicationManager.
5 6 7 8 9 10 |
# File 'lib/spring-jruby/impl/fork/application_manager.rb', line 5 def initialize(app_env) @app_env = app_env @spring_env = Env.new @mutex = Mutex.new @state = :running end |
Instance Attribute Details
#child ⇒ Object (readonly)
Returns the value of attribute child.
3 4 5 |
# File 'lib/spring-jruby/impl/fork/application_manager.rb', line 3 def child @child end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
3 4 5 |
# File 'lib/spring-jruby/impl/fork/application_manager.rb', line 3 def pid @pid end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
3 4 5 |
# File 'lib/spring-jruby/impl/fork/application_manager.rb', line 3 def status @status end |
Instance Method Details
#alive? ⇒ Boolean
34 35 36 |
# File 'lib/spring-jruby/impl/fork/application_manager.rb', line 34 def alive? @pid end |
#restart ⇒ Object
29 30 31 32 |
# File 'lib/spring-jruby/impl/fork/application_manager.rb', line 29 def restart return if @state == :stopping start_child(true) end |
#run(client) ⇒ Object
Returns the name of the screen running the command, or nil if the application process died.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/spring-jruby/impl/fork/application_manager.rb', line 59 def run(client) with_child do child.send_io client child.gets or raise Errno::EPIPE end pid = child.gets.to_i unless pid.zero? log "got worker pid #{pid}" pid end rescue Errno::ECONNRESET, Errno::EPIPE => e log "#{e} while reading from child; returning no pid" nil ensure client.close end |
#start ⇒ Object
25 26 27 |
# File 'lib/spring-jruby/impl/fork/application_manager.rb', line 25 def start start_child end |
#stop ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/spring-jruby/impl/fork/application_manager.rb', line 78 def stop log "stopping" @state = :stopping if pid Process.kill('TERM', pid) Process.wait(pid) end rescue Errno::ESRCH, Errno::ECHILD # Don't care end |
#synchronize ⇒ Object
We’re not using @mutex.synchronize to avoid the weird “<internal:prelude>:10” line which messes with backtraces in e.g. rspec
18 19 20 21 22 23 |
# File 'lib/spring-jruby/impl/fork/application_manager.rb', line 18 def synchronize @mutex.lock yield ensure @mutex.unlock end |