sidekiq-unique-jobs 2.7.0 → 2.7.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: 774a1d7ddc612a093c21bc717c839b2ad6c0eb86
4
- data.tar.gz: 7b4c90512accf84894675887cee3addba328c9d5
3
+ metadata.gz: 1b39f24bdf9c726995309be6197b768d386f10f7
4
+ data.tar.gz: eff0e7d8830cb959a212c1ddb6305eb83a4ecaba
5
5
  SHA512:
6
- metadata.gz: 27f27613ec3338945275678c377ddd77500540ac28ebe4986ef45684c2461b20ea72c7e12c67d80feba466f141295f54bc23bbbfce30dc37304273596befc255
7
- data.tar.gz: ce9a29bdd35166e5bdda72b8f45f48b0048d2f48e678d57c01c082441059f0b192c177d71d1b0e795805340dae7bf85f800bdc2bee609b66fba9b1cbca0c2442
6
+ metadata.gz: a4b47722b22edfb2157dfd13b49b212cf64e860f0c6ee4fee26045ed854a00511c98a8b89a729e6c0329d3033c603b7bb3e7e24b1b3cfe50cf21c13510de2d78
7
+ data.tar.gz: 79c75c467a0ed416b3a5db44d5f1f119df472e1d5ad4aab4fddcf12ee300a6c90f9585b176c4caed2418b74e270993ff912b17d5af772a269d9f34922906a06d
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ Gemfile.lock
7
7
 
8
8
  .ruby-version
9
9
  .idea/
10
+ gemfiles/*.lock
@@ -6,6 +6,12 @@ rvm:
6
6
  - jruby-19mode
7
7
  - rbx-19mode
8
8
  - 2.0.0
9
+ - 2.1.0
10
+ gemfile:
11
+ - gemfiles/sidekiq_2.15.gemfile
12
+ - gemfiles/sidekiq_2.16.gemfile
13
+ - gemfiles/sidekiq_2.17.gemfile
14
+ - gemfiles/sidekiq_develop.gemfile
9
15
  branches:
10
16
  only:
11
17
  - master
@@ -0,0 +1,15 @@
1
+ appraise "sidekiq-develop" do
2
+ gem 'sidekiq', github: 'mperham/sidekiq'
3
+ end
4
+
5
+ appraise "sidekiq-2.17" do
6
+ gem 'sidekiq', '2.17'
7
+ end
8
+
9
+ appraise "sidekiq-2.16" do
10
+ gem "sidekiq", '2.16'
11
+ end
12
+
13
+ appraise "sidekiq-2.15" do
14
+ gem "sidekiq", '2.15'
15
+ end
data/Gemfile CHANGED
@@ -1,10 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
  gemspec
3
3
 
4
- group :development do
5
- gem 'sidekiq', github: 'mperham/sidekiq'
6
- end
7
-
4
+ gem 'appraisal', '~> 1.0.0.beta'
8
5
  gem 'pry'
9
6
  gem 'pry-stack_explorer'
10
7
  gem 'pry-debugger'
data/README.md CHANGED
@@ -24,6 +24,13 @@ All that is required is that you specifically set the sidekiq option for *unique
24
24
  sidekiq_options unique: true
25
25
  ```
26
26
 
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.
30
+
31
+ *If you want the unique job to stick around even after it has been successfully
32
+ processed then just set the unique_unlock_order to anything except `:before_yield` or `:after_yield` (`unique_unlock_order = :never`)
33
+
27
34
  You can also control the expiration length of the uniqueness check. If you want to enforce uniqueness over a longer period than the default of 30 minutes then you can pass the number of seconds you want to use to the sidekiq options:
28
35
 
29
36
  ```ruby
@@ -34,8 +41,9 @@ Requiring the gem in your gemfile should be sufficient to enable unique jobs.
34
41
 
35
42
  ### Finer Control over Uniqueness
36
43
 
37
- Sometimes it is desired to have a finer control over which arguments are used in determining uniqueness of the job, and others may be _transient_. For this use-case, you need to
38
- set `SidekiqUniqueJobs::Config.unique_args_enabled` to true in an initializer, and then defined either `unique_args` method, or a ruby proc.
44
+ Sometimes it is desired to have a finer control over which arguments are used in determining uniqueness of the job, and others may be _transient_. For this use-case, you need to set `SidekiqUniqueJobs::Config.unique_args_enabled` to true in an initializer, and then defined either `unique_args` method, or a ruby proc.
45
+
46
+ The unique_args method need to return an array of values to use for uniqueness check.
39
47
 
40
48
  ```ruby
41
49
  SidekiqUniqueJobs::Config.unique_args_enabled = true
@@ -67,10 +75,7 @@ class UniqueJobWithFilterProc
67
75
  end
68
76
  ```
69
77
 
70
- Note that objects passed into workers are converted to JSON *after* running through client middleware. In server
71
- middleware, the JSON is passed directly to the worker `#perform` method. So, you may run into issues where the
72
- arguments are different when enqueuing than they are when performing. Your `unique_args` method may need to
73
- account for this.
78
+ Note that objects passed into workers are converted to JSON *after* running through client middleware. In server middleware, the JSON is passed directly to the worker `#perform` method. So, you may run into issues where the arguments are different when enqueuing than they are when performing. Your `unique_args` method may need to account for this.
74
79
 
75
80
  ### Unlock Ordering
76
81
 
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rake
2
+ require "rubygems"
3
+ require "bundler/setup"
2
4
  require "bundler/gem_tasks"
3
5
  require 'rspec/core/rake_task'
4
6
 
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "appraisal", "~> 1.0.0.beta"
6
+ gem "pry"
7
+ gem "pry-stack_explorer"
8
+ gem "pry-debugger"
9
+ gem "sidekiq", "2.15"
10
+
11
+ gemspec :path=>".././"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "appraisal", "~> 1.0.0.beta"
6
+ gem "pry"
7
+ gem "pry-stack_explorer"
8
+ gem "pry-debugger"
9
+ gem "sidekiq", "2.16"
10
+
11
+ gemspec :path=>".././"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "appraisal", "~> 1.0.0.beta"
6
+ gem "pry"
7
+ gem "pry-stack_explorer"
8
+ gem "pry-debugger"
9
+ gem "sidekiq", "2.17"
10
+
11
+ gemspec :path=>".././"
@@ -0,0 +1,11 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "appraisal", "~> 1.0.0.beta"
6
+ gem "pry"
7
+ gem "pry-stack_explorer"
8
+ gem "pry-debugger"
9
+ gem "sidekiq", :github=>"mperham/sidekiq"
10
+
11
+ gemspec :path=>".././"
@@ -4,21 +4,45 @@ module SidekiqUniqueJobs
4
4
  module Middleware
5
5
  module Server
6
6
  class UniqueJobs
7
- def call(worker, item, queue)
8
- unlock_order = worker.class.get_sidekiq_options['unique_unlock_order'] ||
9
- SidekiqUniqueJobs::Config.default_unlock_order
7
+ attr_reader :unlock_order
10
8
 
9
+ def call(worker, item, queue)
10
+ set_unlock_order(worker.class)
11
11
  lock_key = payload_hash(item)
12
-
13
- unlocked = unlock_order == :before_yield ? unlock(lock_key).inspect : 0
12
+ unlocked = before_yield? ? unlock(lock_key).inspect : 0
14
13
 
15
14
  yield
16
15
  ensure
17
- if unlock_order == :after_yield || !defined? unlocked || unlocked != 1
16
+ if after_yield? || !defined? unlocked || unlocked != 1
18
17
  unlock(lock_key)
19
18
  end
20
19
  end
21
20
 
21
+ def set_unlock_order(klass)
22
+ @unlock_order = if unlock_order_configured?(klass)
23
+ klass.get_sidekiq_options['unique_unlock_order']
24
+ else
25
+ default_unlock_order
26
+ end
27
+ end
28
+
29
+ def unlock_order_configured?(klass)
30
+ klass.respond_to?(:get_sidekiq_options) &&
31
+ !klass.get_sidekiq_options['unique_unlock_order'].nil?
32
+ end
33
+
34
+ def default_unlock_order
35
+ SidekiqUniqueJobs::Config.default_unlock_order
36
+ end
37
+
38
+ def before_yield?
39
+ unlock_order == :before_yield
40
+ end
41
+
42
+ def after_yield?
43
+ unlock_order == :after_yield
44
+ end
45
+
22
46
  protected
23
47
 
24
48
  def payload_hash(item)
@@ -1,3 +1,3 @@
1
1
  module SidekiqUniqueJobs
2
- VERSION = "2.7.0"
2
+ VERSION = "2.7.1"
3
3
  end
@@ -14,11 +14,11 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "sidekiq-unique-jobs"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = SidekiqUniqueJobs::VERSION
17
- gem.add_dependency 'sidekiq', '~> 2.6'
18
- gem.add_dependency 'mock_redis'
19
- gem.add_development_dependency 'rspec', '>= 2'
20
- gem.add_development_dependency 'rake'
21
- gem.add_development_dependency 'rspec-sidekiq'
22
- gem.add_development_dependency 'activesupport', '~> 3'
23
- gem.add_development_dependency 'simplecov'
17
+ gem.add_dependency 'sidekiq', '~> 2.6'
18
+ gem.add_dependency 'mock_redis'
19
+ gem.add_development_dependency 'rspec', '~> 3.0.0.beta'
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'rspec-sidekiq'
22
+ gem.add_development_dependency 'activesupport', '~> 3'
23
+ gem.add_development_dependency 'simplecov'
24
24
  end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ module SidekiqUniqueJobs
4
+ module Middleware
5
+ module Server
6
+ describe UniqueJobs do
7
+ describe '#unlock_order_configured?' do
8
+ context "when class isn't a Sidekiq::Worker" do
9
+ it "returns false" do
10
+ expect(subject.unlock_order_configured?(Class))
11
+ .to eq(false)
12
+ end
13
+ end
14
+
15
+ context "when get_sidekiq_options[:unique_unlock_order] is nil" do
16
+ it "returns false" do
17
+ expect(subject.unlock_order_configured?(MyWorker))
18
+ .to eq(false)
19
+ end
20
+ end
21
+
22
+ it "returns true when unique_unlock_order has been set" do
23
+ UniqueWorker.sidekiq_options unique_unlock_order: :before_yield
24
+ expect(subject.unlock_order_configured?(UniqueWorker))
25
+ .to eq(true)
26
+ end
27
+ end
28
+
29
+ describe '#set_unlock_order' do
30
+ context "when worker has specified unique_unlock_order" do
31
+ it "changes unlock_order to the configured value" do
32
+ UniqueWorker.sidekiq_options unique_unlock_order: :before_yield
33
+ expect do
34
+ subject.set_unlock_order(UniqueWorker)
35
+ end.to change { subject.unlock_order }.to :before_yield
36
+ end
37
+ end
38
+
39
+ context "when worker hasn't specified unique_unlock_order" do
40
+ it "falls back to configured default_unlock_order" do
41
+ SidekiqUniqueJobs::Config.default_unlock_order = :before_yield
42
+ expect do
43
+ subject.set_unlock_order(UniqueWorker)
44
+ end.to change { subject.unlock_order }.to :before_yield
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#before_yield?' do
50
+ it "returns unlock_order == :before_yield" do
51
+ allow(subject).to receive(:unlock_order).and_return(:after_yield)
52
+ expect(subject.before_yield?).to eq(false)
53
+
54
+ allow(subject).to receive(:unlock_order).and_return(:before_yield)
55
+ expect(subject.before_yield?).to eq(true)
56
+ end
57
+ end
58
+
59
+ describe '#after_yield?' do
60
+ it "returns unlock_order == :before_yield" do
61
+ allow(subject).to receive(:unlock_order).and_return(:before_yield)
62
+ expect(subject.after_yield?).to eq(false)
63
+
64
+ allow(subject).to receive(:unlock_order).and_return(:after_yield)
65
+ expect(subject.after_yield?).to eq(true)
66
+ end
67
+ end
68
+
69
+ describe '#default_unlock_order' do
70
+ it 'returns the default value from config' do
71
+ SidekiqUniqueJobs::Config.default_unlock_order = :before_yield
72
+ expect(subject.default_unlock_order).to eq(:before_yield)
73
+
74
+ SidekiqUniqueJobs::Config.default_unlock_order = :after_yield
75
+ expect(subject.default_unlock_order).to eq(:after_yield)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -3,18 +3,19 @@ require 'sidekiq/worker'
3
3
  require "sidekiq-unique-jobs"
4
4
  require 'sidekiq/scheduled'
5
5
  require 'sidekiq-unique-jobs/middleware/server/unique_jobs'
6
+ require 'rspec-sidekiq'
6
7
 
7
8
  describe "When Sidekiq::Testing is enabled" do
8
9
  describe 'when set to :fake!', sidekiq: :fake do
9
10
  context "with unique worker" do
10
11
  it "does not push duplicate messages" do
11
12
  param = 'work'
12
- expect(UniqueWorker).to have_enqueued_jobs(0)
13
+ expect(UniqueWorker.jobs.size).to eq(0)
13
14
  UniqueWorker.perform_async(param)
14
- expect(UniqueWorker).to have_enqueued_jobs(1)
15
+ expect(UniqueWorker.jobs.size).to eq(1)
15
16
  expect(UniqueWorker).to have_enqueued_job(param)
16
17
  UniqueWorker.perform_async(param)
17
- expect(UniqueWorker).to have_enqueued_jobs(1)
18
+ expect(UniqueWorker.jobs.size).to eq(1)
18
19
  end
19
20
  end
20
21
 
@@ -22,12 +23,12 @@ describe "When Sidekiq::Testing is enabled" do
22
23
 
23
24
  it "pushes duplicates messages" do
24
25
  param = 'work'
25
- expect(MyWorker).to have_enqueued_jobs(0)
26
+ expect(MyWorker.jobs.size).to eq(0)
26
27
  MyWorker.perform_async(param)
27
- expect(MyWorker).to have_enqueued_jobs(1)
28
+ expect(MyWorker.jobs.size).to eq(1)
28
29
  expect(MyWorker).to have_enqueued_job(param)
29
30
  MyWorker.perform_async(param)
30
- expect(MyWorker).to have_enqueued_jobs(2)
31
+ expect(MyWorker.jobs.size).to eq(2)
31
32
  end
32
33
  end
33
34
  end
@@ -14,7 +14,6 @@ require 'sidekiq/util'
14
14
  require 'sidekiq-unique-jobs'
15
15
  Sidekiq.logger.level = Logger::ERROR
16
16
 
17
- require 'sidekiq/testing'
18
17
  require 'rspec-sidekiq'
19
18
 
20
19
  Sidekiq::Testing.disable!
@@ -25,5 +24,16 @@ REDIS = Sidekiq::RedisConnection.create(:url => redis_url, :namespace => 'testy'
25
24
 
26
25
  Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each { |f| require f }
27
26
  RSpec.configure do |config|
28
- config.treat_symbols_as_metadata_keys_with_true_values = true
27
+ # config.treat_symbols_as_metadata_keys_with_true_values = true
28
+ end
29
+
30
+ RSpec::Sidekiq.configure do |config|
31
+ # Clears all job queues before each example
32
+ config.clear_all_enqueued_jobs = true # default => true
33
+
34
+ # Whether to use terminal colours when outputting messages
35
+ config.enable_terminal_colours = true # default => true
36
+
37
+ # Warn when jobs are not enqueued to Redis but to a job array
38
+ config.warn_when_jobs_not_processed_by_sidekiq = true # default => true
29
39
  end
@@ -1,5 +1,5 @@
1
1
  RSpec.configure do |config|
2
- config.before(:each) do # |example| TODO: Add this for RSpec 3
2
+ config.before(:each) do |example|
3
3
  sidekiq = example.metadata[:sidekiq]
4
4
  if sidekiq
5
5
  sidekiq = :fake if sidekiq == true
@@ -7,7 +7,7 @@ RSpec.configure do |config|
7
7
  end
8
8
  end
9
9
 
10
- config.after(:each) do # |example| TODO: Add this for RSpec 3
10
+ config.after(:each) do |example|
11
11
  if sidekiq = example.metadata[:sidekiq]
12
12
  Sidekiq::Testing.disable!
13
13
  end
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-unique-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.7.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: 2013-11-24 00:00:00.000000000 Z
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mock_redis
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2'
47
+ version: 3.0.0.beta
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2'
54
+ version: 3.0.0.beta
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec-sidekiq
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activesupport
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '3'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: simplecov
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: The unique jobs that were removed from sidekiq
@@ -115,14 +115,19 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - .gitignore
119
- - .rspec
120
- - .travis.yml
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Appraisals
121
122
  - CHANGELOG.md
122
123
  - Gemfile
123
124
  - LICENSE
124
125
  - README.md
125
126
  - Rakefile
127
+ - gemfiles/sidekiq_2.15.gemfile
128
+ - gemfiles/sidekiq_2.16.gemfile
129
+ - gemfiles/sidekiq_2.17.gemfile
130
+ - gemfiles/sidekiq_develop.gemfile
126
131
  - lib/sidekiq-unique-jobs.rb
127
132
  - lib/sidekiq-unique-jobs/config.rb
128
133
  - lib/sidekiq-unique-jobs/middleware.rb
@@ -133,6 +138,7 @@ files:
133
138
  - lib/sidekiq-unique-jobs/version.rb
134
139
  - sidekiq-unique-jobs.gemspec
135
140
  - spec/lib/client_spec.rb
141
+ - spec/lib/middleware/server/unique_jobs_spec.rb
136
142
  - spec/lib/sidekiq_testing_enabled_spec.rb
137
143
  - spec/lib/unlock_order_spec.rb
138
144
  - spec/spec_helper.rb
@@ -149,17 +155,17 @@ require_paths:
149
155
  - lib
150
156
  required_ruby_version: !ruby/object:Gem::Requirement
151
157
  requirements:
152
- - - '>='
158
+ - - ">="
153
159
  - !ruby/object:Gem::Version
154
160
  version: '0'
155
161
  required_rubygems_version: !ruby/object:Gem::Requirement
156
162
  requirements:
157
- - - '>='
163
+ - - ">="
158
164
  - !ruby/object:Gem::Version
159
165
  version: '0'
160
166
  requirements: []
161
167
  rubyforge_project:
162
- rubygems_version: 2.1.11
168
+ rubygems_version: 2.2.1
163
169
  signing_key:
164
170
  specification_version: 4
165
171
  summary: The unique jobs that were removed from sidekiq