Class: Spring::ApplicationManager
- Inherits:
-
Object
- Object
- Spring::ApplicationManager
- Defined in:
- lib/spring/application_manager.rb
Instance Attribute Summary collapse
-
#app_env ⇒ Object
readonly
Returns the value of attribute app_env.
-
#child ⇒ Object
readonly
Returns the value of attribute child.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#spring_env ⇒ Object
readonly
Returns the value of attribute spring_env.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(server, app_env) ⇒ ApplicationManager
constructor
A new instance of ApplicationManager.
- #log(message) ⇒ Object
- #restart ⇒ Object
-
#run(client) ⇒ Object
Returns the pid of the process 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.
- #with_child ⇒ Object
Constructor Details
#initialize(server, app_env) ⇒ ApplicationManager
Returns a new instance of ApplicationManager.
9 10 11 12 13 14 |
# File 'lib/spring/application_manager.rb', line 9 def initialize(server, app_env) @server = server @app_env = app_env @spring_env = Env.new @mutex = Mutex.new end |
Instance Attribute Details
#app_env ⇒ Object (readonly)
Returns the value of attribute app_env.
7 8 9 |
# File 'lib/spring/application_manager.rb', line 7 def app_env @app_env end |
#child ⇒ Object (readonly)
Returns the value of attribute child.
7 8 9 |
# File 'lib/spring/application_manager.rb', line 7 def child @child end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
7 8 9 |
# File 'lib/spring/application_manager.rb', line 7 def pid @pid end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
7 8 9 |
# File 'lib/spring/application_manager.rb', line 7 def server @server end |
#spring_env ⇒ Object (readonly)
Returns the value of attribute spring_env.
7 8 9 |
# File 'lib/spring/application_manager.rb', line 7 def spring_env @spring_env end |
Instance Method Details
#alive? ⇒ Boolean
38 39 40 |
# File 'lib/spring/application_manager.rb', line 38 def alive? @pid end |
#log(message) ⇒ Object
16 17 18 |
# File 'lib/spring/application_manager.rb', line 16 def log() server.log() end |
#restart ⇒ Object
34 35 36 |
# File 'lib/spring/application_manager.rb', line 34 def restart start_child(true) end |
#run(client) ⇒ Object
Returns the pid of the process running the command, or nil if the application process died.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/spring/application_manager.rb', line 63 def run(client) with_child do child.send_io client child.gets end pid = child.gets pid = pid.chomp.to_i if pid log "got worker pid #{pid}" pid rescue Errno::ECONNRESET, Errno::EPIPE => e log "#{e} while reading from child; returning no pid" nil ensure client.close end |
#start ⇒ Object
29 30 31 32 |
# File 'lib/spring/application_manager.rb', line 29 def start start_child start_wait_thread end |
#stop ⇒ Object
80 81 82 |
# File 'lib/spring/application_manager.rb', line 80 def stop Process.kill('TERM', pid) if pid 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
22 23 24 25 26 27 |
# File 'lib/spring/application_manager.rb', line 22 def synchronize @mutex.lock yield ensure @mutex.unlock end |
#with_child ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/spring/application_manager.rb', line 42 def with_child synchronize do if alive? begin yield rescue Errno::ECONNRESET, Errno::EPIPE # The child has died but has not been collected by the wait thread yet, # so start a new child and try again. log "child dead; starting" start yield end else log "child not running; starting" start yield end end end |