Skip to content

Commit e0be8b2

Browse files
Adam Greenedefunkt
authored andcommitted
Ensure a terminated worker's job is put in the error queue.
1 parent 6277f41 commit e0be8b2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/resque/errors.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ class NoQueueError < RuntimeError; end
44

55
# Raised when trying to create a job without a class
66
class NoClassError < RuntimeError; end
7+
8+
# Raised when a worker was killed while processing a job.
9+
class DirtyExit < RuntimeError; end
710
end

lib/resque/worker.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,15 @@ def run_hook(name, *args)
326326

327327
# Unregisters ourself as a worker. Useful when shutting down.
328328
def unregister_worker
329+
# If we're still processing a job, make sure it gets logged as a
330+
# failure.
331+
if job
332+
# Ensure the proper worker is attached to this job, even if
333+
# it's not the precise instance that died.
334+
job.worker = self
335+
job.fail(DirtyExit.new)
336+
end
337+
329338
redis.srem(:workers, self)
330339
redis.del("worker:#{self}")
331340
redis.del("worker:#{self}:started")

0 commit comments

Comments
 (0)