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
#parameters, #started_at, #task
Instance Method Summary collapse
-
#initialize(job) ⇒ DelayedJobTrooper
constructor
A new instance of DelayedJobTrooper.
- #max_attempts(job) ⇒ Object
- #reschedule ⇒ Object
- #run ⇒ Object
- #task_name ⇒ Object
Methods inherited from Trooper
#after_run, #before_run, #exception, #name, #start, #status
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
34 35 36 |
# File 'lib/stormtroopers/trooper/delayed_job.rb', line 34 def max_attempts(job) job.max_attempts || Delayed::Worker.max_attempts end |
#reschedule ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stormtroopers/trooper/delayed_job.rb', line 22 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} (#{job.id}) because of #{job.attempts} consecutive failures.") job.hook(:failure) job.fail! end end |
#run ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/stormtroopers/trooper/delayed_job.rb', line 13 def run job.invoke_job job.destroy rescue => error job.last_error = "#{error.message}\n#{error.backtrace.join("\n")}" logger.info "#{job.name} failed with #{error.class.name}: #{error.message} - #{job.attempts} failed attempts" reschedule end |
#task_name ⇒ Object
9 10 11 |
# File 'lib/stormtroopers/trooper/delayed_job.rb', line 9 def task_name "#{@job.name} (#{job.id})" end |