Skip to content
Browse files

Add bulk cancellation API.

  • Loading branch information...
1 parent 57d264f commit 6a8e6a69c28aa8030eaa7dc93941178f67b20c98 @myronmarston myronmarston committed
Showing with 33 additions and 3 deletions.
  1. +4 −0 lib/qless.rb
  2. +1 −1 lib/qless/qless-core
  3. +28 −2 spec/integration/qless_spec.rb
View
4 lib/qless.rb
@@ -194,6 +194,10 @@ def deregister_workers(*worker_names)
_deregister_workers.call([], worker_names)
end
+ def bulk_cancel(jids)
+ @_cancel.call([], jids)
+ end
+
private
def assert_minimum_redis_version(version)
2 lib/qless/qless-core
@@ -1 +1 @@
-Subproject commit b593d849591a677df610c112451040dcb7dd6b81
+Subproject commit 4bb4ff7bbff3d816a85531b3f0c8e625fd9dc3fc
View
30 spec/integration/qless_spec.rb
@@ -2016,9 +2016,35 @@ def registered_worker_names
a = q.put(Qless::Job, {"test" => "depends_canceled"})
b = q.put(Qless::Job, {"test" => "depends_canceled"}, :depends => [a])
- lambda { client.jobs[a].cancel }.should raise_error
+ expect {
+ client.jobs[a].cancel
+ }.to raise_error(/is a dependency/)
end
-
+
+ def create_dep_graph
+ a = q.put(Qless::Job, {"test" => "depends_canceled"})
+ b = q.put(Qless::Job, {"test" => "depends_canceled"}, :depends => [a])
+
+ return a, b
+ end
+
+ it 'can bulk cancel a dependency graph of jobs, regardless of the ordering of the jids' do
+ jids = create_dep_graph
+ expect { client.bulk_cancel(jids) }.to change { q.length }.to(0)
+
+ jids = create_dep_graph
+ expect { client.bulk_cancel(jids.reverse) }.to change { q.length }.to(0)
+ end
+
+ it 'cannot bulk cancel a set of jids that have dependencies outside the jid set' do
+ a = q.put(Qless::Job, {"test" => "depends_canceled"})
+ b = q.put(Qless::Job, {"test" => "depends_canceled"}, :depends => [a])
+ c = q.put(Qless::Job, {"test" => "depends_canceled"})
+ d = q.put(Qless::Job, {"test" => "depends_canceled"}, :depends => [c, a])
+
+ expect { client.bulk_cancel([a, b, c]) }.to raise_error(/is a dependency/)
+ end
+
it "unlocks a job only after its dependencies have completely finished" do
# If we make B depend on A, and then move A through several
# queues, then B should only be availble once A has finished

0 comments on commit 6a8e6a6

Please sign in to comment.
Something went wrong with that request. Please try again.