Class: CapistranoMulticonfigParallel::ChildProcess
- Inherits:
-
Object
- Object
- CapistranoMulticonfigParallel::ChildProcess
- Includes:
- BaseActorHelper
- Defined in:
- lib/capistrano_multiconfig_parallel/celluloid/child_process.rb
Overview
class that is used to execute the capistrano tasks and it is invoked by the celluloid worker
Instance Attribute Summary collapse
-
#actor ⇒ Object
Returns the value of attribute actor.
-
#exit_status ⇒ Object
Returns the value of attribute exit_status.
-
#job ⇒ Object
Returns the value of attribute job.
-
#job_id ⇒ Object
Returns the value of attribute job_id.
-
#options ⇒ Object
Returns the value of attribute options.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#process ⇒ Object
Returns the value of attribute process.
Instance Method Summary collapse
- #async_exception_handler(*data) ⇒ Object
- #check_exit_status ⇒ Object
- #io_callback(io, data) ⇒ Object
- #on_exit(status) ⇒ Object
- #on_input_stdin(data) ⇒ Object
- #on_pid(pid) ⇒ Object
- #on_read_stderr(data) ⇒ Object
- #on_read_stdout(data) ⇒ Object
- #print_error_if_exist ⇒ Object
- #process_finalizer ⇒ Object
- #run_event_machine ⇒ Object
- #setup_attributes ⇒ Object
- #setup_em_error_handler ⇒ Object
- #setup_periodic_timer ⇒ Object
- #start_async_deploy ⇒ Object
- #start_running ⇒ Object
- #watch_handler(process) ⇒ Object
- #work(job, cmd, options = {}) ⇒ Object
Methods included from BaseActorHelper
Instance Attribute Details
#actor ⇒ Object
Returns the value of attribute actor.
7 8 9 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 7 def actor @actor end |
#exit_status ⇒ Object
Returns the value of attribute exit_status.
7 8 9 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 7 def exit_status @exit_status end |
#job ⇒ Object
Returns the value of attribute job.
7 8 9 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 7 def job @job end |
#job_id ⇒ Object
Returns the value of attribute job_id.
7 8 9 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 7 def job_id @job_id end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 7 def end |
#pid ⇒ Object
Returns the value of attribute pid.
7 8 9 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 7 def pid @pid end |
#process ⇒ Object
Returns the value of attribute process.
7 8 9 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 7 def process @process end |
Instance Method Details
#async_exception_handler(*data) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 112 def async_exception_handler(*data) log_to_file "Child process for worker #{@job_id} async_exception_handler disconnected due to error #{data.inspect}" io_callback('stderr', data) @exit_status = 1 check_exit_status end |
#check_exit_status ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 58 def check_exit_status return if @exit_status.blank? @timer.cancel @job.exit_status = @exit_status print_error_if_exist log_to_file("worker #{@job_id} startsnotify finished with exit status #{@exit_status.inspect}") @actor.async.notify_finished(@exit_status) end |
#io_callback(io, data) ⇒ Object
124 125 126 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 124 def io_callback(io, data) log_to_file("#{io.upcase} ---- #{data}", job_id: @job_id) end |
#on_exit(status) ⇒ Object
106 107 108 109 110 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 106 def on_exit(status) log_to_file "Child process for worker #{@job_id} on_exit disconnected due to error #{status.inspect}" @exit_status = status.exitstatus check_exit_status end |
#on_input_stdin(data) ⇒ Object
93 94 95 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 93 def on_input_stdin(data) io_callback('stdin', data) end |
#on_pid(pid) ⇒ Object
89 90 91 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 89 def on_pid(pid) @pid ||= pid end |
#on_read_stderr(data) ⇒ Object
101 102 103 104 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 101 def on_read_stderr(data) @job.save_stderr_error(data) io_callback('stderr', data) end |
#on_read_stdout(data) ⇒ Object
97 98 99 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 97 def on_read_stdout(data) io_callback('stdout', data) end |
#print_error_if_exist ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 67 def print_error_if_exist [@job.stderr_buffer].each do |buffer| buffer.rewind data = buffer.read log_output_error(nil, 'stderr', "Child process for worker #{@job_id} died for reason: #{data}") if data.present? end end |
#process_finalizer ⇒ Object
53 54 55 56 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 53 def process_finalizer EM.stop if EM.reactor_running? terminate end |
#run_event_machine ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 37 def run_event_machine EM.run do EM.next_tick do start_async_deploy end setup_periodic_timer end end |
#setup_attributes ⇒ Object
24 25 26 27 28 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 24 def setup_attributes @actor = .fetch(:actor, nil) @job_id = @job.id @exit_status = nil end |
#setup_em_error_handler ⇒ Object
30 31 32 33 34 35 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 30 def setup_em_error_handler EM.error_handler do|exception| log_error(exception, job_id: @job_id, output: 'stderr') EM.stop end end |
#setup_periodic_timer ⇒ Object
46 47 48 49 50 51 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 46 def setup_periodic_timer @timer = EM::PeriodicTimer.new(0.1) do check_exit_status @timer.cancel if @exit_status.present? end end |
#start_async_deploy ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 75 def start_async_deploy RightScale::RightPopen.popen3_async( @cmd, target: self, environment: .fetch(:environment, nil), pid_handler: :on_pid, input: :on_input_stdin, stdout_handler: :on_read_stdout, stderr_handler: :on_read_stderr, watch_handler: :watch_handler, async_exception_handler: :async_exception_handler, exit_handler: :on_exit) end |
#start_running ⇒ Object
18 19 20 21 22 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 18 def start_running setup_attributes run_event_machine setup_em_error_handler end |
#watch_handler(process) ⇒ Object
119 120 121 122 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 119 def watch_handler(process) @process ||= process check_exit_status end |
#work(job, cmd, options = {}) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 11 def work(job, cmd, = {}) = @job = job @cmd = cmd start_running end |