Class: Spring::ApplicationManager::Worker
- Inherits:
-
Object
- Object
- Spring::ApplicationManager::Worker
- Defined in:
- lib/spring-jruby/impl/pool/application_manager.rb
Instance Attribute Summary collapse
-
#on_done ⇒ Object
Returns the value of attribute on_done.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#screen_name ⇒ Object
readonly
Returns the value of attribute screen_name.
-
#screen_pid ⇒ Object
readonly
Returns the value of attribute screen_pid.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
- #await_boot ⇒ Object
-
#initialize(env, args) ⇒ Worker
constructor
A new instance of Worker.
- #log(message) ⇒ Object
- #spawn_screen(env, args) ⇒ Object
- #start_wait_thread(pid, child) ⇒ Object
Constructor Details
#initialize(env, args) ⇒ Worker
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/spring-jruby/impl/pool/application_manager.rb', line 7 def initialize(env, args) @spring_env = Env.new channel, @remote_socket = WorkerChannel.pair @uuid = File.basename(@remote_socket.path).gsub('.sock', '') Bundler.with_clean_env do spawn_screen( env.merge("SPRING_SOCKET" => @remote_socket.path), args ) end @socket = channel.to_io end |
Instance Attribute Details
#on_done ⇒ Object
Returns the value of attribute on_done.
5 6 7 |
# File 'lib/spring-jruby/impl/pool/application_manager.rb', line 5 def on_done @on_done end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
4 5 6 |
# File 'lib/spring-jruby/impl/pool/application_manager.rb', line 4 def pid @pid end |
#screen_name ⇒ Object (readonly)
Returns the value of attribute screen_name.
4 5 6 |
# File 'lib/spring-jruby/impl/pool/application_manager.rb', line 4 def screen_name @screen_name end |
#screen_pid ⇒ Object (readonly)
Returns the value of attribute screen_pid.
4 5 6 |
# File 'lib/spring-jruby/impl/pool/application_manager.rb', line 4 def screen_pid @screen_pid end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
4 5 6 |
# File 'lib/spring-jruby/impl/pool/application_manager.rb', line 4 def socket @socket end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
4 5 6 |
# File 'lib/spring-jruby/impl/pool/application_manager.rb', line 4 def uuid @uuid end |
Instance Method Details
#await_boot ⇒ Object
35 36 37 38 39 40 |
# File 'lib/spring-jruby/impl/pool/application_manager.rb', line 35 def await_boot Process.detach(screen_pid) @pid = socket.gets.to_i start_wait_thread(pid, socket) unless pid.zero? @remote_socket.close end |
#log(message) ⇒ Object
55 56 57 |
# File 'lib/spring-jruby/impl/pool/application_manager.rb', line 55 def log() @spring_env.log "[worker:#{uuid}] #{message}" end |
#spawn_screen(env, args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/spring-jruby/impl/pool/application_manager.rb', line 22 def spawn_screen(env, args) @screen_name = "spring_#{@uuid}" @screen_pid = Process.spawn( env.merge("SPRING_SCREEN_NAME" => screen_name), "screen", "-d", "-m", "-S", screen_name, *args ) log "(spawn #{@screen_pid})" end |
#start_wait_thread(pid, child) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/spring-jruby/impl/pool/application_manager.rb', line 42 def start_wait_thread(pid, child) Thread.new { begin Process.kill(0, pid) while sleep(1) rescue Errno::ESRCH end log "child #{pid} shutdown" on_done.call(self) if on_done } end |