class Sisyphus::Worker
Constants
- UNCAUGHT_ERROR
Attributes
execution_strategy[R]
job[R]
output[R]
Public Class Methods
new(job, output, execution_strategy)
click to toggle source
# File lib/sisyphus/worker.rb, line 7 def initialize(job, output, execution_strategy) @job = job @output = output @execution_strategy = execution_strategy end
Public Instance Methods
error_handler()
click to toggle source
# File lib/sisyphus/worker.rb, line 32 def error_handler -> { begin output.write UNCAUGHT_ERROR unless stopped? rescue Errno::EAGAIN, Errno::EINTR # Ignore end } end
perform_job()
click to toggle source
# File lib/sisyphus/worker.rb, line 28 def perform_job execution_strategy.execute job, error_handler end
setup()
click to toggle source
# File lib/sisyphus/worker.rb, line 13 def setup job.setup if job.respond_to? :setup end
start()
click to toggle source
# File lib/sisyphus/worker.rb, line 17 def start trap_signals loop do break if stopped? perform_job end exit! 0 end
Private Instance Methods
stop()
click to toggle source
# File lib/sisyphus/worker.rb, line 50 def stop @stopped = true end
stopped?()
click to toggle source
# File lib/sisyphus/worker.rb, line 54 def stopped? @stopped end
trap_signals()
click to toggle source
# File lib/sisyphus/worker.rb, line 44 def trap_signals Signal.trap('INT') do stop end end