class Sisyphus::ForkingExecutionStrategy

Attributes

logger[R]

Public Class Methods

new(logger) click to toggle source
# File lib/sisyphus/forking_execution_strategy.rb, line 6
def initialize(logger)
  @logger = logger
end

Public Instance Methods

execute(job, error_handler = ->{} click to toggle source
# File lib/sisyphus/forking_execution_strategy.rb, line 10
def execute(job, error_handler = ->{})
  if @child_pid = fork
    error_handler.call unless success?
  else
    perform job
  end
end

Private Instance Methods

child_process() click to toggle source
# File lib/sisyphus/forking_execution_strategy.rb, line 43
def child_process
  ChildProcess.new(@child_pid)
end
perform(job) click to toggle source
# File lib/sisyphus/forking_execution_strategy.rb, line 47
def perform(job)
  self.process_name = "Child of worker #{::Process.ppid}"
  begin
    job.perform
    exit! 0
  rescue ::Exception => e
    logger.warn(process_name) { e }
    exit! 1
  end
end
process_name() click to toggle source
# File lib/sisyphus/forking_execution_strategy.rb, line 58
def process_name
  $0
end
process_name=(name) click to toggle source
# File lib/sisyphus/forking_execution_strategy.rb, line 62
def process_name=(name)
  $0 = name
end
success?() click to toggle source
# File lib/sisyphus/forking_execution_strategy.rb, line 39
def success?
  child_process.success?
end