Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix for last_error recording when destroy_failed_jobs = false, max_at…

…tempts = 1
  • Loading branch information...
commit 26f8c2698f40f40bba1958545bc96114cd2f0ea6 1 parent e87d08a
Barnaby Gray authored bkeepers committed
Showing with 24 additions and 2 deletions.
  1. +8 −2 lib/delayed/job.rb
  2. +16 −0 spec/job_spec.rb
View
10 lib/delayed/job.rb
@@ -72,8 +72,14 @@ def reschedule(message, backtrace = [], time = nil)
self.unlock
save!
else
- logger.info "* [JOB] PERMANENTLY removing #{self.name} because of #{attempts} consequetive failures."
- destroy_failed_jobs ? destroy : update_attribute(:failed_at, Delayed::Job.db_time_now)
+ logger.info "* [JOB] PERMANENTLY removing #{self.name} because of #{attempts} consecutive failures."
+ if destroy_failed_jobs
+ destroy
+ else
+ self.failed_at = Delayed::Job.db_time_now
+ self.last_error = message + "\n" + backtrace.join("\n")
+ save!
+ end
end
end
View
16 spec/job_spec.rb
@@ -90,6 +90,22 @@
job.run_at.should < Delayed::Job.db_time_now + 10.minutes
end
+ it "should record last_error when destroy_failed_jobs = false, max_attempts = 1" do
+ Delayed::Job.destroy_failed_jobs = false
+ Delayed::Job::max_attempts = 1
+ Delayed::Job.enqueue ErrorJob.new
+ Delayed::Job.work_off(1)
+
+ job = Delayed::Job.find(:first)
+
+ job.reload
+ job.last_error.should =~ /did not work/
+ job.last_error.should =~ /job_spec.rb:10:in `perform'/
+ job.attempts.should == 1
+
+ job.failed_at.should_not == nil
+ end
+
it "should raise an DeserializationError when the job class is totally unknown" do
job = Delayed::Job.new
Please sign in to comment.
Something went wrong with that request. Please try again.