Skip to content

Commit

Permalink
fix(ordered): remove extra re-enqueues
Browse files Browse the repository at this point in the history
  • Loading branch information
Korotaev Danil committed Oct 3, 2015
1 parent effbbe1 commit d26ed6e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/resque/integration/ordered.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def perform(meta_id, *)
ordered_meta.finish!

i += 1
return continue if max_iterations && i > max_iterations
return continue if max_iterations && i > max_iterations && ordered_queue_size(meta_id) > 0
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/resque/integration/ordered_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,27 @@ class TestJob

expect(TestJob).to receive(:execute).with(kind_of(Resque::Plugins::Meta::Metadata), 1, 10).ordered
expect(TestJob).to receive(:execute).with(kind_of(Resque::Plugins::Meta::Metadata), 1, 20).ordered
expect(TestJob).to_not receive(:continue)

meta_id = TestJob.meta_id(1, 10)
TestJob.perform(meta_id)
expect(TestJob.ordered_queue_size(meta_id)).to eq 0
end

it "reenqueue job after max iterations reached" do
TestJob.enqueue(1, 10)
TestJob.enqueue(1, 20)
TestJob.enqueue(1, 30)
TestJob.enqueue(1, 40)

expect(TestJob).to receive(:execute).with(kind_of(Resque::Plugins::Meta::Metadata), 1, 10).ordered
expect(TestJob).to receive(:execute).with(kind_of(Resque::Plugins::Meta::Metadata), 1, 20).ordered
expect(TestJob).to_not receive(:execute).with(kind_of(Resque::Plugins::Meta::Metadata), 1, 30).ordered
expect(TestJob).to_not receive(:execute).with(kind_of(Resque::Plugins::Meta::Metadata), 1, 40).ordered
expect(TestJob).to receive(:continue)

meta_id = TestJob.meta_id(1, 10)
TestJob.perform(meta_id)
expect(TestJob.ordered_queue_size(meta_id)).to eq 2
end
end

0 comments on commit d26ed6e

Please sign in to comment.