class CapistranoMulticonfigParallel::ProcessRunner

Public Instance Methods

check_exit_status() click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 59
def check_exit_status
  exit_status = @runner_status.exit_status
  return if exit_status.blank?
  @timer.cancel
  if @actor.present? && @actor.respond_to?(:notify_finished)
    log_to_file("#{@actor.class} #{@job_id} startsnotify finished with exit status #{exit_status.inspect}")
    if @actor.respond_to?(:async) && @synchronicity == :async
      @actor.async.notify_finished(exit_status, @runner_status)
    else
      @actor.notify_finished(exit_status, @runner_status)
    end
  end
end
do_right_popen3(synchronicity, command, popen3_options) click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 115
def do_right_popen3(synchronicity, command, popen3_options)
  popen3_options = {
    :target                  => @runner_status,
    :environment             => @options.fetch(:environment, nil),
    :input                   => :on_input_stdin,
    :stdout_handler          => :on_read_stdout,
    :stderr_handler          => :on_read_stderr,
    :watch_handler           => :watch_handler,
    :pid_handler             => :on_pid,
    :timeout_handler         => :on_timeout,
    :size_limit_handler      => :on_size_limit,
    :exit_handler            => :on_exit,
    :async_exception_handler => :async_exception_handler
  }.merge(popen3_options)
  case synchronicity
  when :sync
    result = ::RightScale::RightPopen.popen3_sync(command, popen3_options)
  when :async
    result = ::RightScale::RightPopen.popen3_async(command, popen3_options)
  else
    raise "Uknown synchronicity = #{synchronicity.inspect}"
  end
  result == true
end
do_right_popen3_async( command, popen3_options) click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 144
def do_right_popen3_async( command, popen3_options)
  do_right_popen3(:async, command, popen3_options)
end
do_right_popen3_sync(command, popen3_options) click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 140
def do_right_popen3_sync(command, popen3_options)
  do_right_popen3(:sync, command, popen3_options)
end
process_finalizer() click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 73
def process_finalizer
  EM.stop if EM.reactor_running?
  terminate
end
run_right_popen3() click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 78
def run_right_popen3
  popen3_options = {
    #  :timeout_seconds  => @options.has_key?(:timeout) ? @options[:timeout] : 2,
    :size_limit_bytes => @options[:size_limit_bytes],
    :watch_directory  => @options[:watch_directory],
    :user             => @options[:user],
    :group            => @options[:group],
  }
  command = @runner_status.command
  case @synchronicity
  when :sync
    run_right_popen3_sync(command, popen3_options)
  when :async
    run_right_popen3_async(command, popen3_options)
  else
    raise "unknown synchronicity = #{synchronicity.inspect}"
  end
end
run_right_popen3_async(command, popen3_options) click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 101
def run_right_popen3_async(command, popen3_options)
  EM.run do
    EM.defer do
      begin
        do_right_popen3_async(command, popen3_options)
      rescue Exception => e
        log_error(exception, job_id: @job_id, output: 'stderr')
        EM.stop
      end
    end
    setup_periodic_timer
  end
end
run_right_popen3_sync(command, popen3_options) click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 97
def run_right_popen3_sync(command, popen3_options)
  do_right_popen3_sync(command, popen3_options)
end
setup_attributes() click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 40
def setup_attributes
  @actor = @options.fetch(:actor, nil)
  @job_id = @job.id
end
setup_em_error_handler() click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 45
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() click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 52
def setup_periodic_timer
  @timer = EM::PeriodicTimer.new(0.1) do
    check_exit_status
    @timer.cancel if @runner_status.exit_status.present?
  end
end
start_running() click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 34
def start_running
  setup_attributes
  run_right_popen3
  setup_em_error_handler
end
work(job, cmd, options = {}) click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/process_runner.rb, line 23
def work(job, cmd, options = {})
  @options = options.is_a?(Hash) ? options.symbolize_keys : {}
  @job = job
  @cmd = cmd

  @runner_status_klass = @options[:runner_status_klass].present? ? @options[:runner_status_klass] : RunnerStatus
  @runner_status = @runner_status_klass.new(Actor.current, job, cmd,  @options)
  @synchronicity = @options[:process_sync]
  start_running
end