Skip to content

Commit 766a552

Browse files
author
Aaron Patterson and Terence Lee
committed
rescue Failing jobs and keep stats on it
1 parent 4eb4283 commit 766a552

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/resque/consumer.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ def consume
4747
if job == POISON
4848
shutdown
4949
else
50-
job.run
50+
begin
51+
job.run
52+
rescue Exception
53+
# run failure hooks
54+
Stat << "failed"
55+
end
5156
end
5257
end
5358
end

test/consumer_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ def run
1414
end
1515
end
1616

17+
class FailingJob
18+
def run
19+
raise "fuuuu"
20+
end
21+
end
22+
1723
class Resumer
1824
LATCHES = {}
1925

@@ -130,5 +136,14 @@ def run
130136
assert_equal 1, q.length
131137
assert_equal 0, Actionable.ran.length
132138
end
139+
140+
it "gracefully handles a job failure" do
141+
q = Queue.new(:foo)
142+
c = Consumer.new(q, 1)
143+
q << FailingJob.new
144+
q << Poison.new(c)
145+
c.consume
146+
assert_equal 1, Stat["failed"], 'should have one fail'
147+
end
133148
end
134149
end

0 commit comments

Comments
 (0)