sidekiq-unique-jobs 4.0.18 → 5.0.0
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/.codeclimate.yml +42 -7
- data/.csslintrc +2 -0
- data/.eslintignore +1 -0
- data/.eslintrc +213 -0
- data/.gitignore +2 -0
- data/.rspec +1 -2
- data/.rubocop.yml +19 -0
- data/.simplecov +2 -1
- data/.travis.yml +8 -12
- data/Appraisals +10 -20
- data/CHANGELOG.md +4 -0
- data/Gemfile +10 -6
- data/README.md +16 -2
- data/Rakefile +1 -0
- data/bin/bench +1 -0
- data/bin/jobs +1 -0
- data/circle.yml +6 -3
- data/gemfiles/sidekiq_4.0.gemfile +8 -5
- data/gemfiles/sidekiq_4.1.gemfile +8 -5
- data/gemfiles/{sidekiq_3.1.gemfile → sidekiq_4.2.gemfile} +9 -6
- data/gemfiles/{sidekiq_3.2.gemfile → sidekiq_5.0.gemfile} +9 -6
- data/gemfiles/sidekiq_develop.gemfile +8 -5
- data/lib/sidekiq-unique-jobs.rb +1 -1
- data/lib/sidekiq_unique_jobs/config.rb +1 -9
- data/lib/sidekiq_unique_jobs/constants.rb +1 -0
- data/lib/sidekiq_unique_jobs/core_ext.rb +44 -34
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +1 -1
- data/lib/sidekiq_unique_jobs/script_mock.rb +4 -7
- data/lib/sidekiq_unique_jobs/scripts.rb +9 -8
- data/lib/sidekiq_unique_jobs/testing/sidekiq_overrides.rb +23 -17
- data/lib/sidekiq_unique_jobs/unique_args.rb +1 -1
- data/lib/sidekiq_unique_jobs/unlockable.rb +8 -15
- data/lib/sidekiq_unique_jobs/util.rb +7 -0
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- data/rails_example/.env.test +12 -0
- data/rails_example/.rspec +1 -1
- data/rails_example/Gemfile +12 -9
- data/rails_example/app/controllers/work_controller.rb +16 -2
- data/rails_example/app/models/guest.rb +8 -11
- data/rails_example/app/workers/simple_worker.rb +4 -1
- data/rails_example/app/workers/slow_until_executing_worker.rb +15 -0
- data/rails_example/app/workers/spawn_simple_worker.rb +3 -0
- data/rails_example/app/workers/without_argument_worker.rb +12 -0
- data/rails_example/bin/check_or_setup_db +0 -1
- data/rails_example/common-services.yml +2 -0
- data/rails_example/config/database.yml +2 -2
- data/rails_example/config/environments/development.rb +1 -1
- data/rails_example/config/environments/test.rb +1 -1
- data/rails_example/config/initializers/sidekiq.rb +1 -1
- data/rails_example/config/routes.rb +1 -0
- data/rails_example/config/spring.rb +2 -2
- data/rails_example/docker-compose.yml +19 -38
- data/rails_example/spec/controllers/work_controller_mock_spec.rb +91 -0
- data/rails_example/spec/controllers/work_controller_spec.rb +46 -141
- data/rails_example/spec/rails_helper.rb +1 -2
- data/sidekiq-unique-jobs.gemspec +6 -4
- data/spec/jobs/custom_queue_job.rb +1 -2
- data/spec/jobs/just_a_worker.rb +1 -2
- data/spec/jobs/long_running_job.rb +1 -2
- data/spec/jobs/main_job.rb +1 -2
- data/spec/jobs/my_unique_job.rb +1 -2
- data/spec/jobs/plain_class.rb +1 -2
- data/spec/jobs/test_class.rb +1 -2
- data/spec/jobs/until_and_while_executing_job.rb +1 -2
- data/spec/jobs/until_executing_job.rb +1 -2
- data/spec/jobs/without_argument_job.rb +9 -0
- data/spec/lib/sidekiq_unique_jobs/client/middleware_spec.rb +6 -3
- data/spec/lib/sidekiq_unique_jobs/config_spec.rb +84 -0
- data/spec/lib/sidekiq_unique_jobs/lock/until_and_while_executing_spec.rb +2 -1
- data/spec/lib/sidekiq_unique_jobs/lock/while_executing_spec.rb +2 -2
- data/spec/lib/sidekiq_unique_jobs/script_mock_spec.rb +12 -6
- data/spec/lib/sidekiq_unique_jobs/scripts_spec.rb +0 -5
- data/spec/lib/sidekiq_unique_jobs/sidekiq_testing_enabled_spec.rb +5 -3
- data/spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb +2 -2
- data/spec/lib/sidekiq_unique_jobs/unique_args_spec.rb +23 -7
- data/spec/lib/sidekiq_unique_jobs/unlockable_spec.rb +34 -0
- data/spec/lib/sidekiq_unique_jobs/util_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -14
- data/spec/support/ruby_meta.rb +10 -3
- data/spec/support/sidekiq_meta.rb +2 -3
- metadata +33 -16
- data/gemfiles/sidekiq_2.15.gemfile +0 -9
- data/gemfiles/sidekiq_2.16.gemfile +0 -9
- data/gemfiles/sidekiq_2.17.gemfile +0 -19
- data/gemfiles/sidekiq_3.0.gemfile +0 -19
- data/gemfiles/sidekiq_3.3.gemfile +0 -19
- data/spec/celluloid_with_fallback.rb +0 -18
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
MOCK_REDIS = MockRedis.new
|
4
|
+
|
5
|
+
describe WorkController, 'with mock redis' do
|
6
|
+
before do
|
7
|
+
MOCK_REDIS.keys.each do |key|
|
8
|
+
MOCK_REDIS.del(key)
|
9
|
+
end
|
10
|
+
|
11
|
+
Sidekiq::Queues.clear_all
|
12
|
+
Sidekiq::Worker.clear_all
|
13
|
+
|
14
|
+
SidekiqUniqueJobs.configure do |config|
|
15
|
+
config.redis_test_mode = :mock
|
16
|
+
end
|
17
|
+
allow(Sidekiq).to receive(:redis).and_yield(MOCK_REDIS)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'GET /work/duplicate_simple' do
|
21
|
+
context 'when test mode is fake', sidekiq: :fake do
|
22
|
+
specify do
|
23
|
+
expect { get :duplicate_simple, params: { id: 10 } }
|
24
|
+
.to change { SimpleWorker.jobs.size }
|
25
|
+
.from(0)
|
26
|
+
.to(1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when test mode is disabled', sidekiq: :disable do
|
31
|
+
specify do
|
32
|
+
get :duplicate_simple, params: { id: 11 }
|
33
|
+
Sidekiq.redis do |c|
|
34
|
+
expect(c.keys.size).to eq(2)
|
35
|
+
expect(c.llen('queue:default')).to eq(0)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when test mode is inline', sidekiq: :inline do
|
41
|
+
specify do
|
42
|
+
get :duplicate_simple, params: { id: 12 }
|
43
|
+
Sidekiq.redis do |c|
|
44
|
+
expect(c).to be_a(MockRedis)
|
45
|
+
expect(c.keys.size).to eq(0)
|
46
|
+
expect(c.llen('queue:default')).to eq(0)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'GET /work/duplicate_nested' do
|
53
|
+
context 'when test mode is fake', sidekiq: :fake do
|
54
|
+
specify do
|
55
|
+
expect { get :duplicate_nested, params: { id: 20 } }
|
56
|
+
.to change { SpawnSimpleWorker.jobs.size }
|
57
|
+
.from(0)
|
58
|
+
.to(4)
|
59
|
+
|
60
|
+
SpawnSimpleWorker.perform_one
|
61
|
+
SpawnSimpleWorker.perform_one
|
62
|
+
expect(SpawnSimpleWorker.jobs.size).to eq(2)
|
63
|
+
expect(SimpleWorker.jobs.size).to eq(1)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when test mode is disabled', sidekiq: :disable do
|
68
|
+
specify do
|
69
|
+
get :duplicate_nested, params: { id: 21 }
|
70
|
+
|
71
|
+
Sidekiq.redis do |c|
|
72
|
+
expect(c).to be_a(MockRedis)
|
73
|
+
expect(c.keys.size).to eq(0)
|
74
|
+
expect(c.llen('queue:default')).to eq(0)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when test mode is inline', sidekiq: :inline do
|
80
|
+
specify do
|
81
|
+
get :duplicate_nested, params: { id: 22 }
|
82
|
+
|
83
|
+
Sidekiq.redis do |c|
|
84
|
+
expect(c).to be_a(MockRedis)
|
85
|
+
expect(c.keys.size).to eq(0)
|
86
|
+
expect(c.llen('queue:default')).to eq(0)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -1,170 +1,75 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe WorkController do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
config.redis_test_mode = :redis
|
8
|
-
end
|
9
|
-
|
10
|
-
Sidekiq::Queues.clear_all
|
11
|
-
Sidekiq.redis(&:flushdb)
|
12
|
-
Sidekiq.redis do |c|
|
13
|
-
c.keys.each do |key|
|
14
|
-
c.del(key)
|
15
|
-
end
|
16
|
-
end
|
3
|
+
describe WorkController, 'with real redis' do
|
4
|
+
before(:each) do
|
5
|
+
SidekiqUniqueJobs.configure do |config|
|
6
|
+
config.redis_test_mode = :redis
|
17
7
|
end
|
18
8
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
expect { get :duplicate_simple }
|
23
|
-
.to change { SimpleWorker.jobs.size }
|
24
|
-
.from(0)
|
25
|
-
.to(1)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'when test mode is disabled', sidekiq: :disable do
|
30
|
-
specify do
|
31
|
-
get :duplicate_simple
|
32
|
-
Sidekiq.redis do |c|
|
33
|
-
expect(c.llen('queue:default')).to eq(1)
|
34
|
-
expect(c.keys).to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
9
|
+
Sidekiq::Queues.clear_all
|
10
|
+
Sidekiq.redis(&:flushdb)
|
11
|
+
end
|
38
12
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
13
|
+
describe 'GET /work/duplicate_simple' do
|
14
|
+
context 'when test mode is fake', sidekiq: :fake do
|
15
|
+
specify do
|
16
|
+
expect { get :duplicate_simple, params: { id: 40 } }
|
17
|
+
.to change { SimpleWorker.jobs.size }
|
18
|
+
.from(0)
|
19
|
+
.to(1)
|
47
20
|
end
|
48
21
|
end
|
49
22
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
.from(0)
|
56
|
-
.to(4)
|
57
|
-
|
58
|
-
SpawnSimpleWorker.perform_one
|
59
|
-
SpawnSimpleWorker.perform_one
|
60
|
-
expect(SpawnSimpleWorker.jobs.size).to eq(2)
|
61
|
-
expect(SimpleWorker.jobs.size).to eq(1)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'when test mode is disabled', sidekiq: :disable do
|
66
|
-
specify do
|
67
|
-
get :duplicate_nested
|
68
|
-
|
69
|
-
Sidekiq.redis do |c|
|
70
|
-
expect(c.llen('queue:default')).to eq(4)
|
71
|
-
expect(c.keys).not_to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
|
72
|
-
end
|
23
|
+
context 'when test mode is disabled', sidekiq: :disable do
|
24
|
+
specify do
|
25
|
+
get :duplicate_simple, params: { id: 41 }
|
26
|
+
Sidekiq.redis do |c|
|
27
|
+
expect(c.llen('queue:default')).to eq(1)
|
73
28
|
end
|
74
29
|
end
|
30
|
+
end
|
75
31
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
expect(c.llen('queue:default')).to eq(0)
|
82
|
-
expect(c.keys).not_to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
|
83
|
-
end
|
32
|
+
context 'when test mode is inline', sidekiq: :inline do
|
33
|
+
specify do
|
34
|
+
get :duplicate_simple, params: { id: 42 }
|
35
|
+
Sidekiq.redis do |c|
|
36
|
+
expect(c.llen('queue:default')).to eq(0)
|
84
37
|
end
|
85
38
|
end
|
86
39
|
end
|
87
40
|
end
|
88
41
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
42
|
+
describe 'GET /work/duplicate_nested' do
|
43
|
+
context 'when test mode is fake', sidekiq: :fake do
|
44
|
+
specify do
|
45
|
+
expect { get :duplicate_nested, params: { id: 34 } }
|
46
|
+
.to change { SpawnSimpleWorker.jobs.size }
|
47
|
+
.from(0)
|
48
|
+
.to(4)
|
96
49
|
|
97
|
-
|
98
|
-
|
50
|
+
SpawnSimpleWorker.perform_one
|
51
|
+
SpawnSimpleWorker.perform_one
|
52
|
+
expect(SpawnSimpleWorker.jobs.size).to eq(2)
|
53
|
+
expect(SimpleWorker.jobs.size).to eq(1)
|
99
54
|
end
|
100
|
-
allow(Redis).to receive(:new).and_return(MOCK_REDIS)
|
101
55
|
end
|
102
56
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
expect { get :duplicate_simple }
|
107
|
-
.to change { SimpleWorker.jobs.size }
|
108
|
-
.from(0)
|
109
|
-
.to(1)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'when test mode is disabled', sidekiq: :disable do
|
114
|
-
specify do
|
115
|
-
get :duplicate_simple
|
116
|
-
Sidekiq.redis do |c|
|
117
|
-
expect(c.llen('queue:default')).to eq(1)
|
118
|
-
expect(c.keys).to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
57
|
+
context 'when test mode is disabled', sidekiq: :disable do
|
58
|
+
specify do
|
59
|
+
get :duplicate_nested, params: { id: 35 }
|
122
60
|
|
123
|
-
|
124
|
-
|
125
|
-
get :duplicate_simple
|
126
|
-
Sidekiq.redis do |c|
|
127
|
-
expect(c.llen('queue:default')).to eq(0)
|
128
|
-
expect(c.keys).not_to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
|
129
|
-
end
|
61
|
+
Sidekiq.redis do |c|
|
62
|
+
expect(c.llen('queue:default')).to eq(4)
|
130
63
|
end
|
131
64
|
end
|
132
65
|
end
|
133
66
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
expect { get :duplicate_nested }
|
138
|
-
.to change { SpawnSimpleWorker.jobs.size }
|
139
|
-
.from(0)
|
140
|
-
.to(4)
|
141
|
-
|
142
|
-
SpawnSimpleWorker.perform_one
|
143
|
-
SpawnSimpleWorker.perform_one
|
144
|
-
expect(SpawnSimpleWorker.jobs.size).to eq(2)
|
145
|
-
expect(SimpleWorker.jobs.size).to eq(1)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context 'when test mode is disabled', sidekiq: :disable do
|
150
|
-
specify do
|
151
|
-
get :duplicate_nested
|
152
|
-
|
153
|
-
Sidekiq.redis do |c|
|
154
|
-
expect(c.llen('queue:default')).to eq(4)
|
155
|
-
expect(c.keys).not_to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
context 'when test mode is inline', sidekiq: :inline do
|
161
|
-
specify do
|
162
|
-
get :duplicate_nested
|
67
|
+
context 'when test mode is inline', sidekiq: :inline do
|
68
|
+
specify do
|
69
|
+
get :duplicate_nested, params: { id: 36 }
|
163
70
|
|
164
|
-
|
165
|
-
|
166
|
-
expect(c.keys).not_to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
|
167
|
-
end
|
71
|
+
Sidekiq.redis do |c|
|
72
|
+
expect(c.llen('queue:default')).to eq(0)
|
168
73
|
end
|
169
74
|
end
|
170
75
|
end
|
@@ -5,14 +5,13 @@ require File.expand_path('../../config/environment', __FILE__)
|
|
5
5
|
abort('The Rails environment is running in production mode!') if Rails.env.production?
|
6
6
|
require 'spec_helper'
|
7
7
|
require 'rspec/rails'
|
8
|
+
require 'pry-byebug'
|
8
9
|
require 'sidekiq_unique_jobs/testing'
|
9
10
|
|
10
11
|
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
11
12
|
|
12
13
|
ActiveRecord::Migration.maintain_test_schema!
|
13
14
|
|
14
|
-
MOCK_REDIS ||= MockRedis.new
|
15
|
-
|
16
15
|
RSpec.configure do |config|
|
17
16
|
config.use_transactional_fixtures = true
|
18
17
|
config.infer_spec_type_from_file_location!
|
data/sidekiq-unique-jobs.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# rubocop:disable Style/FileName
|
2
|
+
|
2
3
|
require File.expand_path('../lib/sidekiq_unique_jobs/version', __FILE__)
|
3
4
|
|
4
5
|
Gem::Specification.new do |gem|
|
@@ -8,18 +9,19 @@ Gem::Specification.new do |gem|
|
|
8
9
|
gem.homepage = 'https://github.com/mhenrixon/sidekiq-unique-jobs'
|
9
10
|
gem.license = 'WTFPL-2.0'
|
10
11
|
|
11
|
-
gem.executables = %w
|
12
|
+
gem.executables = %w[jobs]
|
12
13
|
gem.files = `git ls-files`.split("\n")
|
13
14
|
gem.test_files = `git ls-files -- test/*`.split("\n")
|
14
15
|
gem.name = 'sidekiq-unique-jobs'
|
15
16
|
gem.require_paths = ['lib']
|
16
17
|
gem.post_install_message = 'WARNING: VERSION 4.0.0 HAS BREAKING CHANGES! Please see Readme for info'
|
17
18
|
gem.version = SidekiqUniqueJobs::VERSION
|
18
|
-
gem.add_dependency 'sidekiq', '>=
|
19
|
+
gem.add_dependency 'sidekiq', '>= 4.0'
|
19
20
|
gem.add_dependency 'thor', '>= 0'
|
20
21
|
gem.add_development_dependency 'rspec', '~> 3.1'
|
21
22
|
gem.add_development_dependency 'rake'
|
22
|
-
gem.add_development_dependency 'rubocop'
|
23
23
|
gem.add_development_dependency 'timecop'
|
24
24
|
gem.add_development_dependency 'yard'
|
25
|
+
gem.add_development_dependency 'gem-release'
|
26
|
+
gem.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.0'
|
25
27
|
end
|
data/spec/jobs/just_a_worker.rb
CHANGED
data/spec/jobs/main_job.rb
CHANGED
data/spec/jobs/my_unique_job.rb
CHANGED
data/spec/jobs/plain_class.rb
CHANGED
data/spec/jobs/test_class.rb
CHANGED
@@ -10,18 +10,21 @@ RSpec.describe SidekiqUniqueJobs::Client::Middleware do
|
|
10
10
|
|
11
11
|
describe 'with real redis' do
|
12
12
|
before do
|
13
|
+
if defined?(Sidekiq::Extensions) && Sidekiq::Extensions.respond_to?(:enable_delay!)
|
14
|
+
Sidekiq::Extensions.enable_delay!
|
15
|
+
end
|
13
16
|
Sidekiq.redis = REDIS
|
14
17
|
Sidekiq.redis(&:flushdb)
|
15
18
|
end
|
16
19
|
|
17
20
|
describe 'when a job is already scheduled' do
|
18
|
-
it 'processes jobs properly'
|
21
|
+
it 'processes jobs properly' do
|
19
22
|
Sidekiq::Testing.disable! do
|
20
23
|
jid = NotifyWorker.perform_in(1, 183, 'xxxx')
|
21
24
|
expect(jid).not_to eq(nil)
|
22
25
|
Sidekiq.redis do |c|
|
23
26
|
expect(c.zcard('schedule')).to eq(1)
|
24
|
-
expected = %w
|
27
|
+
expected = %w[schedule uniquejobs:6e47d668ad22db2a3ba0afd331514ce2 uniquejobs]
|
25
28
|
expect(c.keys).to match_array(expected)
|
26
29
|
end
|
27
30
|
sleep 1
|
@@ -39,7 +42,7 @@ RSpec.describe SidekiqUniqueJobs::Client::Middleware do
|
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
42
|
-
it 'rejects nested subsequent jobs with the same arguments'
|
45
|
+
it 'rejects nested subsequent jobs with the same arguments' do
|
43
46
|
Sidekiq::Testing.disable! do
|
44
47
|
expect(SimpleWorker.perform_async(1)).not_to eq(nil)
|
45
48
|
expect(SimpleWorker.perform_async(1)).to eq(nil)
|