Permalink
Browse files

Extract log_exception method so that applications can use it as a hoo…

…k to supply custom exception logging/notification, like Hoptoad for example.
  • Loading branch information...
1 parent 0be1cfa commit 3d52303959723bd9c1aa3505bbcfe079c29d58fb @lukemelia lukemelia committed Nov 8, 2008
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/delayed/job.rb
View
@@ -107,8 +107,7 @@ def self.reserve(max_run_time = 4.hours)
logger.warn "* [JOB] failed to aquire exclusive lock for #{job.name}"
rescue StandardError => e
job.reschedule e.message
- logger.error "* [JOB] #{job.name} failed with #{e.class.name}: #{e.message} - #{job.attempts} failed attempts"
- logger.error(e)
+ log_exception(job, error)
return job
end
end
@@ -155,6 +154,12 @@ def unlock
self.locked_by = nil
end
+ # This is a good hook if you need to report job processing errors in additional or different ways
+ def self.log_exception(job, error)
+ logger.error "* [JOB] #{job.name} failed with #{error.class.name}: #{error.message} - #{job.attempts} failed attempts"
+ logger.error(error)
+ end
+
def self.work_off(num = 100)
success, failure = 0, 0

0 comments on commit 3d52303

Please sign in to comment.