Skip to content

Instantly share code, notes, and snippets.

@skippy
Created March 8, 2010 23:56
Show Gist options
  • Save skippy/325965 to your computer and use it in GitHub Desktop.
Save skippy/325965 to your computer and use it in GitHub Desktop.
module Resque
# Raised when a worker was killed while processing a job.
class DirtyExit < RuntimeError; end
class Worker
module KillPatch
module InstanceMethods
def unregister_worker_with_error_job(*args)
if self.job
recreated_job = nil
begin
recreated_job = Resque::Job.new(self.job['queue'], self.job['payload'])
# needed for exception handling... this is technically incorrect as it should be
# setting the old worker instance...the one that was killed
recreated_job.worker = self
raise Resque::DirtyExit, "The job was not completed when its worker was terminated"
rescue Exception => e
recreated_job.fail(e) if recreated_job
end
end
unregister_worker_without_error_job(*args)
redis.del("worker:#{self}") #noticed that this wasn't being cleared out at all...
end
end
def self.included(receiver)
receiver.send :include, InstanceMethods
receiver.class_eval do
alias_method_chain :unregister_worker, :error_job
end
end
end
end
end
Resque::Worker.send :include, Resque::Worker::KillPatch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment