Permalink
Browse files

raise an exception instead of returning false when max retries has be…

…en exceeded for a job
  • Loading branch information...
1 parent 5c120c1 commit 5a1e1fa005f2d453a890cb80886cdb31df924f31 @freels committed Oct 7, 2010
Showing with 16 additions and 5 deletions.
  1. +14 −3 lib/kestrel/client/transactional.rb
  2. +2 −2 spec/kestrel/client/transactional_spec.rb
@@ -8,6 +8,13 @@ class MultipleQueueException < StandardError; end
# there is no current open transaction
class NoOpenTransaction < StandardError; end
+ # Raised when a retry fails when max retries is exceeded
+ class RetriesExceeded < StandardError
+ def initialize(job)
+ super "Max retries of #{job.retries} exceeded for item: #{job.job.inspect}"
+ end
+ end
+
class RetryableJob < Struct.new(:retries, :job); end
# Number of times to retry a job before giving up
@@ -94,10 +101,14 @@ def retry(item = nil)
job.retries += 1
- client.set(current_queue + "_errors", job) if job.retries < @max_retries
- close_last_transaction
+ if job.retries < @max_retries
+ client.set(current_queue + "_errors", job)
+ else
+ raise RetriesExceeded.new(job)
+ end
- job.retries < @max_retries
+ ensure
+ close_last_transaction
end
private
@@ -83,7 +83,7 @@ def get_job
get_job.should == :mcguffin
@kestrel.current_try.should == Kestrel::Client::Transactional::DEFAULT_RETRIES
- @kestrel.retry
+ lambda { @kestrel.retry }.should raise_error(Kestrel::Client::Transactional::RetriesExceeded)
@kestrel.get(@queue) # simulate next get run
end
end
@@ -207,7 +207,7 @@ def get_job
mock(@raw_kestrel_client).set(@queue + "_errors", anything).never
mock(@raw_kestrel_client).get_from_last(@queue + "_errors/close")
@kestrel.get(@queue)
- @kestrel.retry.should be_false
+ lambda { @kestrel.retry }.should raise_error(Kestrel::Client::Transactional::RetriesExceeded)
end
it "closes an open transaction with no retries" do

0 comments on commit 5a1e1fa

Please sign in to comment.