Class: Stormtroopers::DelayedJobTrooper
- Defined in:
- lib/stormtroopers/trooper/delayed_job.rb
Instance Attribute Summary collapse
-
#job ⇒ Object
readonly
Returns the value of attribute job.
Attributes inherited from Trooper
Instance Method Summary collapse
-
#initialize(job) ⇒ DelayedJobTrooper
constructor
A new instance of DelayedJobTrooper.
- #max_attempts(job) ⇒ Object
- #reschedule ⇒ Object
- #run ⇒ Object
Methods inherited from Trooper
#after_run, #before_run, #exception, #logger
Constructor Details
#initialize(job) ⇒ DelayedJobTrooper
Returns a new instance of DelayedJobTrooper.
5 6 7 |
# File 'lib/stormtroopers/trooper/delayed_job.rb', line 5 def initialize(job) @job = job end |
Instance Attribute Details
#job ⇒ Object (readonly)
Returns the value of attribute job.
3 4 5 |
# File 'lib/stormtroopers/trooper/delayed_job.rb', line 3 def job @job end |
Instance Method Details
#max_attempts(job) ⇒ Object
30 31 32 |
# File 'lib/stormtroopers/trooper/delayed_job.rb', line 30 def max_attempts(job) job.max_attempts || Delayed::Worker.max_attempts end |
#reschedule ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/stormtroopers/trooper/delayed_job.rb', line 18 def reschedule if (job.attempts += 1) < max_attempts(job) job.run_at = job.reschedule_at job.unlock job.save! else logger.error("PERMANENTLY removing #{job.name} because of #{job.attempts} consecutive failures.") job.hook(:failure) job.fail! end end |
#run ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/stormtroopers/trooper/delayed_job.rb', line 9 def run job.invoke_job job.destroy rescue => error job.last_error = "#{error.}\n#{error.backtrace.join("\n")}" logger.info "#{job.name} failed with #{error.class.name}: #{error.} - #{job.attempts} failed attempts" reschedule end |