sidekiq-unique-jobs 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sidekiq-unique-jobs might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/sidekiq-unique-jobs/payload_helper.rb +9 -4
- data/lib/sidekiq-unique-jobs/version.rb +1 -1
- data/spec/lib/client_spec.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00887f13a1ac00f86bf1eb51c3ba8aaa231907c7
|
4
|
+
data.tar.gz: dfb021d98a405c372f668ac21ed0693e3989fe16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a4a08153027e4a057e8ed629b0a80451188bd29a232f9075dce6a00e5b876f60e332e27fc2623e43fdcffecfd3f305ef3faa524de3b7a0d35061694f050e3bb
|
7
|
+
data.tar.gz: 9103f93d5c224044d2c28e3fb9f58c900cd88b43efb5983c7c83fc8deb9ed4d9129d1213b0da1b2575f8d50242dd6432273c4c7ffe6c7d3f6387ac99af1753b3
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# SidekiqUniqueJobs [![Build Status](https://travis-ci.org/
|
1
|
+
# SidekiqUniqueJobs [![Build Status](https://travis-ci.org/mhenrixon/sidekiq-unique-jobs.png?branch=master)](https://travis-ci.org/mhenrixon/sidekiq-unique-jobs) [![Code Climate](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs.png)](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs)
|
2
2
|
|
3
3
|
The missing unique jobs for sidekiq
|
4
4
|
|
@@ -25,8 +25,8 @@ sidekiq_options unique: true
|
|
25
25
|
```
|
26
26
|
|
27
27
|
For jobs scheduled in the future it is possible to set for how long the job
|
28
|
-
should be unique. The job will be unique for the number of seconds configured
|
29
|
-
or until the job has been completed.
|
28
|
+
should be unique. The job will be unique for the number of seconds configured (default 30 minutes)
|
29
|
+
or until the job has been completed. Thus, the job will be unique for the shorter of the two. Note that Sidekiq versions before 3.0 will remove job keys after an hour, which means jobs can remain unique for at most an hour.
|
30
30
|
|
31
31
|
*If you want the unique job to stick around even after it has been successfully
|
32
32
|
processed then just set the unique_unlock_order to anything except `:before_yield` or `:after_yield` (`unique_unlock_order = :never`)
|
@@ -1,13 +1,18 @@
|
|
1
1
|
module SidekiqUniqueJobs
|
2
2
|
class PayloadHelper
|
3
3
|
def self.get_payload(klass, queue, *args)
|
4
|
-
|
5
|
-
|
4
|
+
unique_on_all_queues = false
|
5
|
+
if SidekiqUniqueJobs::Config.unique_args_enabled?
|
6
|
+
worker_class = klass.constantize
|
7
|
+
args = yield_unique_args(worker_class, *args)
|
8
|
+
unique_on_all_queues = worker_class.get_sidekiq_options['unique_on_all_queues']
|
9
|
+
end
|
10
|
+
md5_arguments = {:class => klass, :args => args}
|
11
|
+
md5_arguments[:queue] = queue unless unique_on_all_queues
|
6
12
|
"#{SidekiqUniqueJobs::Config.unique_prefix}:#{Digest::MD5.hexdigest(Sidekiq.dump_json(md5_arguments))}"
|
7
13
|
end
|
8
14
|
|
9
|
-
def self.yield_unique_args(
|
10
|
-
worker_class = klass.constantize
|
15
|
+
def self.yield_unique_args(worker_class, args)
|
11
16
|
unique_args = worker_class.get_sidekiq_options['unique_args']
|
12
17
|
filtered_args = if unique_args
|
13
18
|
case unique_args
|
data/spec/lib/client_spec.rb
CHANGED
@@ -32,6 +32,16 @@ describe "Client" do
|
|
32
32
|
expect(result).to eq 1
|
33
33
|
end
|
34
34
|
|
35
|
+
it 'does push duplicate messages to different queues' do
|
36
|
+
QueueWorker.sidekiq_options :unique => true
|
37
|
+
Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue', 'args' => [1, 2])
|
38
|
+
Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue2', 'args' => [1, 2])
|
39
|
+
q1_length = Sidekiq.redis {|c| c.llen("queue:customqueue") }
|
40
|
+
q2_length = Sidekiq.redis {|c| c.llen("queue:customqueue2") }
|
41
|
+
expect(q1_length).to eq 1
|
42
|
+
expect(q2_length).to eq 1
|
43
|
+
end
|
44
|
+
|
35
45
|
it 'does not queue duplicates when when calling delay' do
|
36
46
|
10.times { PlainClass.delay(unique: true, queue: 'customqueue').run(1) }
|
37
47
|
result = Sidekiq.redis {|c| c.llen("queue:customqueue") }
|
@@ -115,6 +125,20 @@ describe "Client" do
|
|
115
125
|
result = Sidekiq.redis {|c| c.llen("queue:customqueue") }
|
116
126
|
expect(result).to eq 1
|
117
127
|
end
|
128
|
+
|
129
|
+
describe 'when unique_on_all_queues is set' do
|
130
|
+
before { QueueWorker.sidekiq_options :unique => true, :unique_on_all_queues => true }
|
131
|
+
before { QueueWorker.sidekiq_options :unique => true }
|
132
|
+
it 'does not push duplicate messages on different queues' do
|
133
|
+
Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue', 'args' => [1, 2])
|
134
|
+
Sidekiq::Client.push('class' => QueueWorker, 'queue' => 'customqueue2', 'args' => [1, 2])
|
135
|
+
q1_length = Sidekiq.redis {|c| c.llen("queue:customqueue") }
|
136
|
+
q2_length = Sidekiq.redis {|c| c.llen("queue:customqueue2") }
|
137
|
+
expect(q1_length).to eq 1
|
138
|
+
expect(q2_length).to eq 0
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
118
142
|
end
|
119
143
|
|
120
144
|
# TODO: If anyone know of a better way to check that the expiration for scheduled
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-unique-jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Henriksson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|