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)
163163 end
164164 end
165165
166- ensure
167166 unregister_worker
167+ rescue Exception => exception
168+ unregister_worker ( exception )
168169 end
169170
170171 # DEPRECATED. Processes a single job. If none is given, it will
@@ -411,15 +412,15 @@ def run_hook(name, *args)
411412 end
412413
413414 # Unregisters ourself as a worker. Useful when shutting down.
414- def unregister_worker
415+ def unregister_worker ( exception = nil )
415416 # If we're still processing a job, make sure it gets logged as a
416417 # failure.
417418 if ( hash = processing ) && !hash . empty?
418419 job = Job . new ( hash [ 'queue' ] , hash [ 'payload' ] )
419420 # Ensure the proper worker is attached to this job, even if
420421 # it's not the precise instance that died.
421422 job . worker = self
422- job . fail ( DirtyExit . new )
423+ job . fail ( exception || DirtyExit . new )
423424 end
424425
425426 redis . srem ( :workers , self )
Original file line number Diff line number Diff line change 4343 end
4444 end
4545
46- it "fails uncompleted jobs on exit" do
46+ it "fails uncompleted jobs with DirtyExit by default on exit" do
4747 job = Resque ::Job . new ( :jobs , { 'class' => 'GoodJob' , 'args' => "blah" } )
4848 @worker . working_on ( job )
4949 @worker . unregister_worker
5050 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' ] )
5160 end
5261
5362 class ::SimpleJobWithFailureHandling
You can’t perform that action at this time.
0 commit comments