Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
5391eda
Fix a typo in the README
bkirz Mar 10, 2014
76541a3
Add ruby 2.1 to travis build.
myronmarston Mar 18, 2014
4836c79
Fix brittle test.
myronmarston Mar 19, 2014
3262720
`debugger` won't install on ruby 2.0+.
myronmarston Mar 19, 2014
eb8837b
Singleton classes are included in `ancestors` in ruby 2.1.
myronmarston Mar 19, 2014
8eade0c
Use something more intention revealing.
myronmarston Mar 19, 2014
861dc50
Merge pull request #182 from seomoz/add-2.1-to-build
myronmarston Mar 19, 2014
2dbed77
Improve RetryExceptions middleware to support exception-dependent bac…
myronmarston Apr 17, 2014
258f283
Merge pull request #184 from seomoz/pass-error-to-backoff-strategy
myronmarston Apr 17, 2014
f4e7181
Update to qless-core master.
myronmarston May 19, 2014
cd64bff
Add a `Job#spawned_from` method.
myronmarston May 19, 2014
a05faff
Merge pull request #189 from seomoz/spawned_from
myronmarston May 19, 2014
2c837f0
Pull in qless-core version that provides requeue.
myronmarston Jun 12, 2014
d1f8e83
Rename `move` to `dequeue`.
myronmarston Jun 12, 2014
da32c98
Use new `requeue` qless-core command.
myronmarston Jun 12, 2014
afd909e
Merge pull request #192 from seomoz/use-qless-core-requeue
myronmarston Jun 16, 2014
2a38b99
add after_retry callback handler for RetryExceptions middleware
Jun 18, 2014
e17fd1f
add an after_requeue callback to RequeueExceptions
Jun 18, 2014
cc7d858
check block.nil? instead of block_given?
Jun 18, 2014
b80544c
only allow one callback and provide explicit method for setting callback
Jun 19, 2014
dacfb7c
get rid of unnecessary test config code
Jun 19, 2014
1647ad2
Merge pull request #194 from seomoz/retry-and-requeue-callbacks
proby Jun 19, 2014
74a672b
Fix typo.
myronmarston Jul 30, 2014
515cdc8
Merge pull request #200 from seomoz/fix-typo
myronmarston Jul 30, 2014
0fa4402
merging upstream
Aug 8, 2014
09a5ee3
fix test
Aug 8, 2014
627a36d
fix requeue from losing throttles
May 4, 2015
dd87a47
Fix brittle test.
myronmarston Mar 19, 2014
0c68724
Use something more intention revealing.
myronmarston Mar 19, 2014
3ca9a66
Improve RetryExceptions middleware to support exception-dependent bac…
myronmarston Apr 17, 2014
ec963e3
Rename `move` to `dequeue`.
myronmarston Jun 12, 2014
4c95952
Use new `requeue` qless-core command.
myronmarston Jun 12, 2014
1a63c47
add after_retry callback handler for RetryExceptions middleware
Jun 18, 2014
b49e454
add an after_requeue callback to RequeueExceptions
Jun 18, 2014
0f7370b
check block.nil? instead of block_given?
Jun 18, 2014
e0d9cdc
only allow one callback and provide explicit method for setting callback
Jun 19, 2014
094bbc1
get rid of unnecessary test config code
Jun 19, 2014
eb0b5a7
Fix typo.
myronmarston Jul 30, 2014
18ad696
fix requeue from losing throttles
May 4, 2015
0fe9ee6
fix reeqeueue
May 6, 2015
d9712a9
Merge branch 'fix-requeue' of github.com:backupify/qless into fix-req…
May 6, 2015
484c387
undo bad merge
May 6, 2015
41859e7
fix bad merge
May 6, 2015
02ff8a4
fix bad merge
May 6, 2015
3fc6de1
wip
May 6, 2015
4a013c2
test fixes, cleanup
May 8, 2015
b1eed41
strong test
May 11, 2015
7e6592e
peer review
May 12, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add an after_requeue callback to RequeueExceptions
  • Loading branch information
Patrick Roby committed Jun 18, 2014
commit e17fd1f5c3920e80f586d6914ee96232c9c801c6
9 changes: 8 additions & 1 deletion lib/qless/middleware/requeue_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ def raise_if_exhausted_requeues(error, requeues)
end
end

def requeue_on(*exceptions, options)
def requeue_on(*exceptions, options, &block)
after_requeue_callbacks << block if block_given?
RequeueableException.from_splat_and_options(
*exceptions, options).each do |exc|
requeueable_exceptions[exc.klass] = exc
end
end

def after_requeue_callbacks
@after_requeue_callbacks ||= []
end

def around_perform(job)
super
rescue *requeueable_exceptions.keys => e
Expand All @@ -55,6 +60,8 @@ def around_perform(job)

requeues_by_exception[config.klass.name] += 1
job.requeue(job.queue_name, delay: config.delay, data: job.data)

after_requeue_callbacks.each { |callback| callback.call(e, job) }
end

def requeueable_exceptions
Expand Down
49 changes: 45 additions & 4 deletions spec/unit/middleware/requeue_exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def around_perform(job)
matched_exception_2 = KeyError
unmatched_exception = RegexpError

let(:requeue_on_args) do
[matched_exception_1, matched_exception_2, MessageSpecificException,
delay_range: delay_range, max_attempts: max_attempts]
end

module MessageSpecificException
def self.===(other)
ArgumentError === other && other.message.include?("foo")
Expand All @@ -36,16 +41,32 @@ def self.===(other)

before do
container.extend(RequeueExceptions)
container.requeue_on(matched_exception_1, matched_exception_2,
MessageSpecificException,
delay_range: delay_range,
max_attempts: max_attempts)
container.requeue_on(*requeue_on_args)
end

def add_requeue_callback
callback = ->(error, job) { callback_catcher << [error, job] }
container.after_requeue_callbacks << callback
end

def callback_catcher
@callback_catcher ||= []
end

def perform
container.around_perform(job)
end

describe '.requeue_on' do
it 'accepts a block to set an after requeue callback' do
container.extend(RequeueExceptions)

expect {
container.requeue_on(*requeue_on_args) { |*| true }
}.to change {container.after_requeue_callbacks.size }.from(0).to(1)
end
end

context 'when no exception is raised' do
before { container.perform = -> { } }

Expand All @@ -62,6 +83,16 @@ def perform
job.should_not_receive(:requeue)
expect { perform }.to raise_error(unmatched_exception)
end

context 'when an after requeue callback is set' do
before { add_requeue_callback }

it 'does not call the callback' do
expect { perform }.to raise_error(unmatched_exception)

expect(callback_catcher.size).to eq(0)
end
end
end

shared_context "requeues on matching exception" do |exception, exception_name|
Expand Down Expand Up @@ -129,6 +160,16 @@ def perform

expect { perform }.to raise_error(exception)
end

context 'when an after requeue callback is set' do
before { add_requeue_callback }

it 'calls the callback' do
expect {
perform
}.to change { callback_catcher.size }.from(0).to(1)
end
end
end

context "when a matched exception is raised" do
Expand Down