Skip to content

Commit 55de1d7

Browse files
lmarlowdefunkt
authored andcommitted
Allow around_perform hooks to see the return value from a job
1 parent 077494d commit 55de1d7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/resque/job.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ def perform
140140
else
141141
lambda do
142142
job.send(hook, *job_args) do
143-
job.perform(*job_args)
143+
result = job.perform(*job_args)
144144
job_was_performed = true
145+
result
145146
end
146147
end
147148
end

test/job_plugins_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,27 @@ def self.around_perform(history)
177177
assert_equal false, result, "perform returned false"
178178
assert_equal [:around_perform, :around_perform0], history
179179
end
180+
181+
module AroundPerformGetsJobResult
182+
@@result = nil
183+
def last_job_result
184+
@@result
185+
end
186+
187+
def around_perform_gets_job_result(*args)
188+
@@result = yield
189+
end
190+
end
191+
192+
class AroundPerformJobWithReturnValue < GoodJob
193+
extend AroundPerformGetsJobResult
194+
end
195+
196+
test "the job is aborted if an around_perform hook does not yield" do
197+
result = perform_job(AroundPerformJobWithReturnValue, 'Bob')
198+
assert_equal true, result, "perform returned true"
199+
assert_equal 'Good job, Bob', AroundPerformJobWithReturnValue.last_job_result
200+
end
180201
end
181202

182203
context "Resque::Plugin ordering on_failure" do

0 commit comments

Comments
 (0)