Class: Spring::ApplicationManager
- Inherits:
-
Object
- Object
- Spring::ApplicationManager
- Includes:
- Mutex_m
- Defined in:
- lib/spring/application_manager.rb
Instance Attribute Summary collapse
-
#child ⇒ Object
readonly
Returns the value of attribute child.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(env) ⇒ ApplicationManager
constructor
A new instance of ApplicationManager.
- #restart ⇒ Object
-
#run(client) ⇒ Object
Returns the pid of the process running the command, or nil if the application process died.
- #start ⇒ Object
Constructor Details
#initialize(env) ⇒ ApplicationManager
Returns a new instance of ApplicationManager.
11 12 13 14 |
# File 'lib/spring/application_manager.rb', line 11 def initialize(env) super() @env = env end |
Instance Attribute Details
#child ⇒ Object (readonly)
Returns the value of attribute child.
9 10 11 |
# File 'lib/spring/application_manager.rb', line 9 def child @child end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
9 10 11 |
# File 'lib/spring/application_manager.rb', line 9 def env @env end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
9 10 11 |
# File 'lib/spring/application_manager.rb', line 9 def pid @pid end |
Instance Method Details
#alive? ⇒ Boolean
28 29 30 |
# File 'lib/spring/application_manager.rb', line 28 def alive? @pid end |
#restart ⇒ Object
21 22 23 24 25 26 |
# File 'lib/spring/application_manager.rb', line 21 def restart # Restarting is a background operation. If it fails, we don't want # any terminal output. The user will see the output when they next # try to run a command. start_child(true) end |
#run(client) ⇒ Object
Returns the pid of the process running the command, or nil if the application process died.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/spring/application_manager.rb', line 33 def run(client) @client = client synchronize do if alive? begin child.send_io @client rescue Errno::EPIPE # EPIPE indicates child has died but has not been collected by the wait thread yet start child.send_io @client end else start child.send_io @client end end child.gets.chomp.to_i # get the pid rescue Errno::ECONNRESET, Errno::EPIPE nil ensure @client.close @client = nil end |
#start ⇒ Object
16 17 18 19 |
# File 'lib/spring/application_manager.rb', line 16 def start start_child start_wait_thread end |