Class: CapistranoMulticonfigParallel::ChildProcess
- Inherits:
-
Object
- Object
- CapistranoMulticonfigParallel::ChildProcess
- Includes:
- Celluloid, Celluloid::Logger
- 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.
-
#debug_enabled ⇒ Object
Returns the value of attribute debug_enabled.
-
#exit_status ⇒ Object
Returns the value of attribute exit_status.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#job_id ⇒ Object
Returns the value of attribute job_id.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#process ⇒ Object
Returns the value of attribute process.
-
#worker_log ⇒ Object
Returns the value of attribute worker_log.
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
- #process_finalizer ⇒ Object
- #set_worker_log ⇒ Object
- #start_async_deploy(cmd, options) ⇒ Object
- #watch_handler(process) ⇒ Object
- #work(cmd, options = {}) ⇒ Object
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 |
#debug_enabled ⇒ Object
Returns the value of attribute debug_enabled.
7 8 9 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 7 def debug_enabled @debug_enabled 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 |
#filename ⇒ Object
Returns the value of attribute filename.
7 8 9 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 7 def filename @filename 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 |
#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 |
#worker_log ⇒ Object
Returns the value of attribute worker_log.
7 8 9 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 7 def worker_log @worker_log end |
Instance Method Details
#async_exception_handler(*data) ⇒ Object
95 96 97 98 99 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 95 def async_exception_handler(*data) @worker_log.debug "Child process for worker #{@job_id} async_exception_handler disconnected due to error #{data.inspect}" if @debug_enabled io_callback('stderr', data) @exit_status = 1 end |
#check_exit_status ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 49 def check_exit_status return unless @exit_status.present? if [:dry_run] debug("worker #{@actor.job_id} starts execute deploy") if @debug_enabled @actor.async.execute_deploy elsif !@actor.worker_finshed? debug("worker #{@actor.job_id} startsnotify finished") if @debug_enabled @actor.notify_finished(@exit_status) end end |
#io_callback(io, data) ⇒ Object
105 106 107 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 105 def io_callback(io, data) @worker_log.debug("#{io.upcase} ---- #{data}") end |
#on_exit(status) ⇒ Object
90 91 92 93 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 90 def on_exit(status) @worker_log.debug "Child process for worker #{@job_id} on_exit disconnected due to error #{status.inspect}" if @debug_enabled @exit_status = status end |
#on_input_stdin(data) ⇒ Object
78 79 80 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 78 def on_input_stdin(data) io_callback('stdin', data) end |
#on_pid(pid) ⇒ Object
74 75 76 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 74 def on_pid(pid) @pid ||= pid end |
#on_read_stderr(data) ⇒ Object
86 87 88 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 86 def on_read_stderr(data) io_callback('stderr', data) end |
#on_read_stdout(data) ⇒ Object
82 83 84 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 82 def on_read_stdout(data) io_callback('stdout', data) end |
#process_finalizer ⇒ Object
44 45 46 47 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 44 def process_finalizer @timer.cancel EM.stop if EM.reactor_running? end |
#set_worker_log ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 32 def set_worker_log FileUtils.mkdir_p(CapistranoMulticonfigParallel.log_directory) unless File.directory?(CapistranoMulticonfigParallel.log_directory) @filename = File.join(CapistranoMulticonfigParallel.log_directory, "worker_#{@actor.job_id}.log") FileUtils.rm_rf(@filename) if File.file?(@filename) && !@actor.crashed? && ([:dry_run] || @actor.executed_dry_run != true) @worker_log = ::Logger.new(@filename) @worker_log.level = ::Logger::Severity::DEBUG @worker_log.formatter = proc do |severity, datetime, progname, msg| date_format = datetime.strftime('%Y-%m-%d %H:%M:%S') "[#{date_format}] #{severity} (#{progname}): #{msg}\n" end end |
#start_async_deploy(cmd, options) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 60 def start_async_deploy(cmd, ) RightScale::RightPopen.popen3_async( cmd, target: self, environment: [:environment].present? ? [: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 |
#watch_handler(process) ⇒ Object
101 102 103 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 101 def watch_handler(process) @process ||= process end |
#work(cmd, options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 11 def work(cmd, = {}) = @actor = .fetch(:actor, nil) @job_id = @actor.job_id @debug_enabled = @actor.debug_enabled? set_worker_log EM.run do EM.next_tick do start_async_deploy(cmd, ) end @timer = EM::PeriodicTimer.new(0.1) do check_exit_status end end EM.error_handler do|e| @worker_log.debug "Error during event loop for worker #{@job_id}: #{e.inspect}" if @debug_enabled @worker_log.debug e.backtrace if @debug_enabled EM.stop end end |