Skip to content

Commit

Permalink
fixed a defect where exceptions in the failure backend would cause th…
Browse files Browse the repository at this point in the history
…e chile process to terminate like the parent
  • Loading branch information
kemper authored and defunkt committed Feb 4, 2011
1 parent 5765fe1 commit a4b19d4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/resque/worker.rb
Expand Up @@ -162,7 +162,11 @@ def perform(job)
job.perform
rescue Object => e
log "#{job.inspect} failed: #{e.inspect}"
job.fail(e)
begin
job.fail(e)
rescue Object => e
log "Received exception when reporting failure: #{e.inspect}"
end
failed!
else
log "done: #{job.inspect}"
Expand Down
14 changes: 14 additions & 0 deletions test/test_helper.rb
Expand Up @@ -114,3 +114,17 @@ def self.perform
raise SyntaxError, "Extra Bad job!"
end
end

class BadFailureBackend < Resque::Failure::Base
def save
raise Exception.new("Failure backend error")
end
end

def with_failure_backend(failure_backend, &block)
previous_backend = Resque::Failure.backend
Resque::Failure.backend = failure_backend
yield block
ensure
Resque::Failure.backend = previous_backend
end
7 changes: 7 additions & 0 deletions test/worker_test.rb
Expand Up @@ -25,6 +25,13 @@
assert_equal('Extra Bad job!', Resque::Failure.all['error'])
end

test "does not allow exceptions from failure backend to escape" do
job = Resque::Job.new(:jobs, {})
with_failure_backend BadFailureBackend do
@worker.perform job
end
end

test "fails uncompleted jobs on exit" do
job = Resque::Job.new(:jobs, [GoodJob, "blah"])
@worker.working_on(job)
Expand Down

0 comments on commit a4b19d4

Please sign in to comment.