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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f966944556a4eade8e0cd88092db81ce2aaf79f
4
- data.tar.gz: 73ceb2cff924bedb9eb7aa20d50b594cabd582c1
3
+ metadata.gz: 00887f13a1ac00f86bf1eb51c3ba8aaa231907c7
4
+ data.tar.gz: dfb021d98a405c372f668ac21ed0693e3989fe16
5
5
  SHA512:
6
- metadata.gz: 0646749915775d78d40a01667f37642a0dcb6f9748cad2700b7e7957f39735631643b76024ef505363a433c1da305c157218a9bea80c6292344cbcebc9078a8a
7
- data.tar.gz: 23ce922714c75e7c33caf45983bca4a103b75514cf78e90137c937dfbb894456391009ed3dd1911283a3728f85f86d58b2e4f282e82f675b6c32678a5b3a9522
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/form26/sidekiq-unique-jobs.png?branch=master)](https://travis-ci.org/form26/sidekiq-unique-jobs) [![Code Climate](https://codeclimate.com/github/form26/sidekiq-unique-jobs.png)](https://codeclimate.com/github/form26/sidekiq-unique-jobs)
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
- args = yield_unique_args(klass, *args) if SidekiqUniqueJobs::Config.unique_args_enabled?
5
- md5_arguments = {:class => klass, :queue => queue, :args => args}
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(klass, 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
@@ -1,3 +1,3 @@
1
1
  module SidekiqUniqueJobs
2
- VERSION = "3.0.0"
2
+ VERSION = "3.0.1"
3
3
  end
@@ -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.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-05-01 00:00:00.000000000 Z
11
+ date: 2014-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq