Created
March 8, 2011 19:48
-
-
Save chrisvariety/860883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Delayed | |
class Worker | |
def handle_failed_job(job, error) | |
ExceptionNotifier.notify(error, :data => {:session => job.attributes}) | |
job.last_error = error.message + "\n" + error.backtrace.join("\n") | |
say "* [JOB] #{name} failed with #{error.class.name}: #{error.message} - #{job.attempts} failed attempts", Logger::ERROR | |
reschedule(job) | |
end | |
end | |
class PerformableMethod | |
def perform | |
load(object).send(method, *args.map{|a| load(a)}) | |
rescue Exception => e | |
ExceptionNotifier.notify(e, :data => {:session => {:object => object.inspect, :loaded_object => load(object).inspect, :method => method, :args => args.inspect}}) | |
raise e | |
end | |
private | |
def load(obj) | |
if STRING_FORMAT === obj | |
$1.constantize.load_for_delayed_job($2) | |
else | |
obj | |
end | |
rescue => e | |
ExceptionNotifier.notify(e, :data => {:session => {:object => object.inspect, :method => method.inspect, :args => args.inspect}}) | |
Delayed::Worker.logger.warn "Could not load object for job: #{e.message}" | |
raise PerformableMethod::LoadError | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment