Skip to content

Commit

Permalink
Handle more than just StandardError-subclassed exceptions.
Browse files Browse the repository at this point in the history
We want to handle ALL exceptions. Otherwise, a poorly behaved bit of code could kill a worker.  Usually, you don't want to handle all exceptions since you want to let ruby's built-in signal-handling code work (e.g. so that ctrl-c can kill a script).  We handle signals manually here, though.
  • Loading branch information
myronmarston committed May 22, 2012
1 parent b0565e9 commit 4a8f14e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/qless/worker.rb
Expand Up @@ -78,7 +78,7 @@ def work(interval = 5.0)

def perform(job)
around_perform(job)
rescue => error
rescue Exception => error
fail_job(job, error)
else
job.complete unless job.state_changed?
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/worker_spec.rb
Expand Up @@ -17,13 +17,13 @@ class MyJobClass; end
worker.perform(job)
end

it 'fails the job if performing it raises an error' do
MyJobClass.stub(:perform) { raise StandardError.new("boom") }
it 'fails the job if performing it raises an error, including root exceptions' do
MyJobClass.stub(:perform) { raise Exception.new("boom") }
expected_line_number = __LINE__ - 1
job.should respond_to(:fail).with(2).arguments

job.should_receive(:fail) do |group, message|
group.should eq("Qless::MyJobClass:StandardError")
group.should eq("Qless::MyJobClass:Exception")
message.should include("boom")
message.should include("#{__FILE__}:#{expected_line_number}")
end
Expand Down

0 comments on commit 4a8f14e

Please sign in to comment.