Skip to content

Commit e011827

Browse files
malomalodefunkt
authored andcommitted
Exception class recorded when a Error is raised in a worker.
1 parent 187c2f9 commit e011827

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

lib/resque/failure/redis.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def save
77
data = {
88
:failed_at => Time.now.strftime("%Y/%m/%d %H:%M:%S"),
99
:payload => payload,
10+
:exception => exception.class.to_s,
1011
:error => exception.to_s,
1112
:backtrace => exception.backtrace,
1213
:worker => worker.to_s,

lib/resque/server/views/failed.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
<dd><code><%= job['payload']['class'] %></code></dd>
2121
<dt>Arguments</dt>
2222
<dd><pre><%=h show_args(job['payload']['args']) %></pre></dd>
23+
<dt>Exception</td>
24+
<dd><code><%= job['exception'] %></code></dd>
2325
<dt>Error</dt>
2426
<dd class='error'>
2527
<a href="#" class="backtrace"><%= h(job['error']) %></a>

test/test_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,9 @@ def self.perform(name)
9494
"Good job, #{name}"
9595
end
9696
end
97+
98+
class BadJobWithSyntaxError
99+
def self.perform
100+
raise SyntaxError, "Extra Bad job!"
101+
end
102+
end

test/worker_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
@worker.work(0)
1818
assert_equal 1, Resque::Failure.count
1919
end
20+
21+
test "failed jobs report excpetion and message" do
22+
Resque::Job.create(:jobs, BadJobWithSyntaxError)
23+
@worker.work(0)
24+
assert_equal('SyntaxError', Resque::Failure.all['exception'])
25+
assert_equal('Extra Bad job!', Resque::Failure.all['error'])
26+
end
2027

2128
test "can peek at failed jobs" do
2229
10.times { Resque::Job.create(:jobs, BadJob) }

0 commit comments

Comments
 (0)