Class: Sisyphus::Worker
- Inherits:
-
Object
- Object
- Sisyphus::Worker
- Defined in:
- lib/sisyphus/worker.rb
Constant Summary collapse
- UNCAUGHT_ERROR =
'.'
Instance Attribute Summary collapse
-
#execution_strategy ⇒ Object
readonly
Returns the value of attribute execution_strategy.
-
#job ⇒ Object
readonly
Returns the value of attribute job.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #error_handler ⇒ Object
-
#initialize(job, output, execution_strategy) ⇒ Worker
constructor
A new instance of Worker.
- #perform_job ⇒ Object
- #setup ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(job, output, execution_strategy) ⇒ Worker
Returns a new instance of Worker.
7 8 9 10 11 |
# File 'lib/sisyphus/worker.rb', line 7 def initialize(job, output, execution_strategy) @job = job @output = output @execution_strategy = execution_strategy end |
Instance Attribute Details
#execution_strategy ⇒ Object (readonly)
Returns the value of attribute execution_strategy.
5 6 7 |
# File 'lib/sisyphus/worker.rb', line 5 def execution_strategy @execution_strategy end |
#job ⇒ Object (readonly)
Returns the value of attribute job.
5 6 7 |
# File 'lib/sisyphus/worker.rb', line 5 def job @job end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
5 6 7 |
# File 'lib/sisyphus/worker.rb', line 5 def output @output end |
Instance Method Details
#error_handler ⇒ Object
32 33 34 35 36 37 38 39 40 |
# 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 ⇒ Object
28 29 30 |
# File 'lib/sisyphus/worker.rb', line 28 def perform_job execution_strategy.execute job, error_handler end |
#setup ⇒ Object
13 14 15 |
# File 'lib/sisyphus/worker.rb', line 13 def setup job.setup if job.respond_to? :setup end |
#start ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sisyphus/worker.rb', line 17 def start trap_signals loop do break if stopped? perform_job end exit! 0 end |