File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -163,8 +163,9 @@ def work(interval = 5.0, &block)
163
163
end
164
164
end
165
165
166
- ensure
167
166
unregister_worker
167
+ rescue Exception => exception
168
+ unregister_worker ( exception )
168
169
end
169
170
170
171
# DEPRECATED. Processes a single job. If none is given, it will
@@ -411,15 +412,15 @@ def run_hook(name, *args)
411
412
end
412
413
413
414
# Unregisters ourself as a worker. Useful when shutting down.
414
- def unregister_worker
415
+ def unregister_worker ( exception = nil )
415
416
# If we're still processing a job, make sure it gets logged as a
416
417
# failure.
417
418
if ( hash = processing ) && !hash . empty?
418
419
job = Job . new ( hash [ 'queue' ] , hash [ 'payload' ] )
419
420
# Ensure the proper worker is attached to this job, even if
420
421
# it's not the precise instance that died.
421
422
job . worker = self
422
- job . fail ( DirtyExit . new )
423
+ job . fail ( exception || DirtyExit . new )
423
424
end
424
425
425
426
redis . srem ( :workers , self )
Original file line number Diff line number Diff line change 43
43
end
44
44
end
45
45
46
- it "fails uncompleted jobs on exit" do
46
+ it "fails uncompleted jobs with DirtyExit by default on exit" do
47
47
job = Resque ::Job . new ( :jobs , { 'class' => 'GoodJob' , 'args' => "blah" } )
48
48
@worker . working_on ( job )
49
49
@worker . unregister_worker
50
50
assert_equal 1 , Resque ::Failure . count
51
+ assert_equal ( 'Resque::DirtyExit' , Resque ::Failure . all [ 'exception' ] )
52
+ end
53
+
54
+ test "fails uncompleted jobs with worker exception on exit" do
55
+ job = Resque ::Job . new ( :jobs , { 'class' => 'GoodJob' , 'args' => "blah" } )
56
+ @worker . working_on ( job )
57
+ @worker . unregister_worker ( StandardError . new )
58
+ assert_equal 1 , Resque ::Failure . count
59
+ assert_equal ( 'StandardError' , Resque ::Failure . all [ 'exception' ] )
51
60
end
52
61
53
62
class ::SimpleJobWithFailureHandling
You can’t perform that action at this time.
0 commit comments