Class: CapistranoMulticonfigParallel::ChildProcess
- Inherits:
-
Object
- Object
- CapistranoMulticonfigParallel::ChildProcess
- Includes:
- ApplicationHelper, 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.
-
#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
- #process_finalizer ⇒ Object
- #start_async_deploy(cmd, options) ⇒ Object
- #watch_handler(process) ⇒ Object
- #work(job, cmd, options = {}) ⇒ Object
Methods included from ApplicationHelper
parse_task_string, strip_characters_from_string
Methods included from StagesHelper
check_stage_path, checks_paths, fetch_stages, fetch_stages_paths, sorted_paths, stages_paths
Methods included from CoreHelper
app_configuration, app_debug_enabled?, app_logger, ask_confirm, check_terminal_tty, debug_websocket?, execute_with_rescue, find_config_type, find_loaded_gem, find_worker_log, force_confirmation, format_error, log_error, log_to_file, rescue_error, rescue_interrupt, show_warning, websocket_config, websocket_server_config
Methods included from InternalHelper
config_file, custom_commands, default_internal_config, detect_root, enable_main_log_file, find_env_multi_cap_root, internal_config_directory, internal_config_file, log_directory, main_log_file, root, try_detect_capfile
Instance Attribute Details
#actor ⇒ Object
Returns the value of attribute actor.
10 11 12 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 10 def actor @actor end |
#exit_status ⇒ Object
Returns the value of attribute exit_status.
10 11 12 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 10 def exit_status @exit_status end |
#job ⇒ Object
Returns the value of attribute job.
10 11 12 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 10 def job @job end |
#job_id ⇒ Object
Returns the value of attribute job_id.
10 11 12 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 10 def job_id @job_id end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 10 def @options end |
#pid ⇒ Object
Returns the value of attribute pid.
10 11 12 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 10 def pid @pid end |
#process ⇒ Object
Returns the value of attribute process.
10 11 12 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 10 def process @process end |
Instance Method Details
#async_exception_handler(*data) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 84 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
39 40 41 42 43 44 45 46 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 39 def check_exit_status log_to_file("worker #{@job_id} checking exit status #{@exit_status.inspect}") if @exit_status.present? return if @exit_status.blank? @job.exit_status = @exit_status log_to_file("worker #{@job_id} startsnotify finished") @actor.async.notify_finished(@exit_status) @timer.cancel end |
#io_callback(io, data) ⇒ Object
95 96 97 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 95 def io_callback(io, data) log_to_file("#{io.upcase} ---- #{data}", @job_id) end |
#on_exit(status) ⇒ Object
78 79 80 81 82 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 78 def on_exit(status) @exit_status = status.exitstatus log_to_file "Child process for worker #{@job_id} on_exit disconnected due to error #{status.inspect} and #{@exit_status.inspect}" check_exit_status end |
#on_input_stdin(data) ⇒ Object
66 67 68 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 66 def on_input_stdin(data) io_callback('stdin', data) end |
#on_pid(pid) ⇒ Object
62 63 64 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 62 def on_pid(pid) @pid ||= pid end |
#on_read_stderr(data) ⇒ Object
74 75 76 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 74 def on_read_stderr(data) io_callback('stderr', data) end |
#on_read_stdout(data) ⇒ Object
70 71 72 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 70 def on_read_stdout(data) io_callback('stdout', data) end |
#process_finalizer ⇒ Object
35 36 37 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 35 def process_finalizer EM.stop if EM.reactor_running? end |
#start_async_deploy(cmd, options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 48 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
91 92 93 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 91 def watch_handler(process) @process ||= process end |
#work(job, cmd, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/capistrano_multiconfig_parallel/celluloid/child_process.rb', line 14 def work(job, cmd, = {}) @options = @job = job @actor = @options.fetch(:actor, nil) @job_id = @job.id @exit_status = nil 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| log_to_file("Error during event loop for worker #{@job_id}: #{e.inspect}", @job_id) log_to_file(e.backtrace, @job_id) EM.stop end end |