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.

Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +42 -7
  3. data/.csslintrc +2 -0
  4. data/.eslintignore +1 -0
  5. data/.eslintrc +213 -0
  6. data/.gitignore +2 -0
  7. data/.rspec +1 -2
  8. data/.rubocop.yml +19 -0
  9. data/.simplecov +2 -1
  10. data/.travis.yml +8 -12
  11. data/Appraisals +10 -20
  12. data/CHANGELOG.md +4 -0
  13. data/Gemfile +10 -6
  14. data/README.md +16 -2
  15. data/Rakefile +1 -0
  16. data/bin/bench +1 -0
  17. data/bin/jobs +1 -0
  18. data/circle.yml +6 -3
  19. data/gemfiles/sidekiq_4.0.gemfile +8 -5
  20. data/gemfiles/sidekiq_4.1.gemfile +8 -5
  21. data/gemfiles/{sidekiq_3.1.gemfile → sidekiq_4.2.gemfile} +9 -6
  22. data/gemfiles/{sidekiq_3.2.gemfile → sidekiq_5.0.gemfile} +9 -6
  23. data/gemfiles/sidekiq_develop.gemfile +8 -5
  24. data/lib/sidekiq-unique-jobs.rb +1 -1
  25. data/lib/sidekiq_unique_jobs/config.rb +1 -9
  26. data/lib/sidekiq_unique_jobs/constants.rb +1 -0
  27. data/lib/sidekiq_unique_jobs/core_ext.rb +44 -34
  28. data/lib/sidekiq_unique_jobs/lock/while_executing.rb +1 -1
  29. data/lib/sidekiq_unique_jobs/script_mock.rb +4 -7
  30. data/lib/sidekiq_unique_jobs/scripts.rb +9 -8
  31. data/lib/sidekiq_unique_jobs/testing/sidekiq_overrides.rb +23 -17
  32. data/lib/sidekiq_unique_jobs/unique_args.rb +1 -1
  33. data/lib/sidekiq_unique_jobs/unlockable.rb +8 -15
  34. data/lib/sidekiq_unique_jobs/util.rb +7 -0
  35. data/lib/sidekiq_unique_jobs/version.rb +1 -1
  36. data/rails_example/.env.test +12 -0
  37. data/rails_example/.rspec +1 -1
  38. data/rails_example/Gemfile +12 -9
  39. data/rails_example/app/controllers/work_controller.rb +16 -2
  40. data/rails_example/app/models/guest.rb +8 -11
  41. data/rails_example/app/workers/simple_worker.rb +4 -1
  42. data/rails_example/app/workers/slow_until_executing_worker.rb +15 -0
  43. data/rails_example/app/workers/spawn_simple_worker.rb +3 -0
  44. data/rails_example/app/workers/without_argument_worker.rb +12 -0
  45. data/rails_example/bin/check_or_setup_db +0 -1
  46. data/rails_example/common-services.yml +2 -0
  47. data/rails_example/config/database.yml +2 -2
  48. data/rails_example/config/environments/development.rb +1 -1
  49. data/rails_example/config/environments/test.rb +1 -1
  50. data/rails_example/config/initializers/sidekiq.rb +1 -1
  51. data/rails_example/config/routes.rb +1 -0
  52. data/rails_example/config/spring.rb +2 -2
  53. data/rails_example/docker-compose.yml +19 -38
  54. data/rails_example/spec/controllers/work_controller_mock_spec.rb +91 -0
  55. data/rails_example/spec/controllers/work_controller_spec.rb +46 -141
  56. data/rails_example/spec/rails_helper.rb +1 -2
  57. data/sidekiq-unique-jobs.gemspec +6 -4
  58. data/spec/jobs/custom_queue_job.rb +1 -2
  59. data/spec/jobs/just_a_worker.rb +1 -2
  60. data/spec/jobs/long_running_job.rb +1 -2
  61. data/spec/jobs/main_job.rb +1 -2
  62. data/spec/jobs/my_unique_job.rb +1 -2
  63. data/spec/jobs/plain_class.rb +1 -2
  64. data/spec/jobs/test_class.rb +1 -2
  65. data/spec/jobs/until_and_while_executing_job.rb +1 -2
  66. data/spec/jobs/until_executing_job.rb +1 -2
  67. data/spec/jobs/without_argument_job.rb +9 -0
  68. data/spec/lib/sidekiq_unique_jobs/client/middleware_spec.rb +6 -3
  69. data/spec/lib/sidekiq_unique_jobs/config_spec.rb +84 -0
  70. data/spec/lib/sidekiq_unique_jobs/lock/until_and_while_executing_spec.rb +2 -1
  71. data/spec/lib/sidekiq_unique_jobs/lock/while_executing_spec.rb +2 -2
  72. data/spec/lib/sidekiq_unique_jobs/script_mock_spec.rb +12 -6
  73. data/spec/lib/sidekiq_unique_jobs/scripts_spec.rb +0 -5
  74. data/spec/lib/sidekiq_unique_jobs/sidekiq_testing_enabled_spec.rb +5 -3
  75. data/spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb +2 -2
  76. data/spec/lib/sidekiq_unique_jobs/unique_args_spec.rb +23 -7
  77. data/spec/lib/sidekiq_unique_jobs/unlockable_spec.rb +34 -0
  78. data/spec/lib/sidekiq_unique_jobs/util_spec.rb +1 -1
  79. data/spec/spec_helper.rb +3 -14
  80. data/spec/support/ruby_meta.rb +10 -3
  81. data/spec/support/sidekiq_meta.rb +2 -3
  82. metadata +33 -16
  83. data/gemfiles/sidekiq_2.15.gemfile +0 -9
  84. data/gemfiles/sidekiq_2.16.gemfile +0 -9
  85. data/gemfiles/sidekiq_2.17.gemfile +0 -19
  86. data/gemfiles/sidekiq_3.0.gemfile +0 -19
  87. data/gemfiles/sidekiq_3.3.gemfile +0 -19
  88. 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
- context 'with real redis' do
5
- before(:each) do
6
- SidekiqUniqueJobs.configure do |config|
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
- describe 'GET /work/duplicate_simple' do
20
- context 'when test mode is fake', sidekiq: :fake do
21
- specify do
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
- context 'when test mode is inline', sidekiq: :inline do
40
- specify do
41
- get :duplicate_simple
42
- Sidekiq.redis do |c|
43
- expect(c.llen('queue:default')).to eq(0)
44
- expect(c.keys).not_to include('uniquejobs:83bda9f47b05071ffcb35cbb59e1fada')
45
- end
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
- describe 'GET /work/duplicate_nested' do
51
- context 'when test mode is fake', sidekiq: :fake do
52
- specify do
53
- expect { get :duplicate_nested }
54
- .to change { SpawnSimpleWorker.jobs.size }
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
- context 'when test mode is inline', sidekiq: :inline do
77
- specify do
78
- get :duplicate_nested
79
-
80
- Sidekiq.redis do |c|
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
- context 'with mock_redis' do
90
- before do
91
- SidekiqUniqueJobs.configure do |config|
92
- config.redis_test_mode = :mock
93
- end
94
- Sidekiq::Queues.clear_all
95
- Sidekiq::Worker.clear_all
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
- MOCK_REDIS.keys.each do |key|
98
- MOCK_REDIS.del(key)
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
- describe 'GET /work/duplicate_simple' do
104
- context 'when test mode is fake', sidekiq: :fake do
105
- specify do
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
- context 'when test mode is inline', sidekiq: :inline do
124
- specify do
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
- describe 'GET /work/duplicate_nested' do
135
- context 'when test mode is fake', sidekiq: :fake do
136
- specify do
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
- Sidekiq.redis do |c|
165
- expect(c.llen('queue:default')).to eq(0)
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!
@@ -1,4 +1,5 @@
1
- # -*- encoding: utf-8 -*-
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(jobs)
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', '>= 2.6'
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
@@ -1,6 +1,5 @@
1
1
  class CustomQueueJob
2
2
  include Sidekiq::Worker
3
3
  sidekiq_options queue: :customqueue
4
- def perform(_)
5
- end
4
+ def perform(_); end
6
5
  end
@@ -3,6 +3,5 @@ class JustAWorker
3
3
 
4
4
  sidekiq_options unique: :until_executed, queue: 'testqueue'
5
5
 
6
- def perform
7
- end
6
+ def perform; end
8
7
  end
@@ -2,6 +2,5 @@ class LongRunningJob
2
2
  include Sidekiq::Worker
3
3
  sidekiq_options queue: :customqueue, retry: true, unique: :until_and_while_executing,
4
4
  run_lock_expiration: 7_200, retry_count: 10
5
- def perform(_one, _two)
6
- end
5
+ def perform(_one, _two); end
7
6
  end
@@ -3,6 +3,5 @@ class MainJob
3
3
  sidekiq_options queue: :customqueue, unique: :until_executed,
4
4
  log_duplicate_payload: true
5
5
 
6
- def perform(_)
7
- end
6
+ def perform(_); end
8
7
  end
@@ -7,6 +7,5 @@ class MyUniqueJob
7
7
  unique_expiration: 7_200,
8
8
  retry_count: 10
9
9
  )
10
- def perform(_one, _two)
11
- end
10
+ def perform(_one, _two); end
12
11
  end
@@ -1,4 +1,3 @@
1
1
  class PlainClass
2
- def run(_x)
3
- end
2
+ def run(_x); end
4
3
  end
@@ -1,4 +1,3 @@
1
1
  class TestClass
2
- def self.run(_)
3
- end
2
+ def self.run(_); end
4
3
  end
@@ -3,6 +3,5 @@ class UntilAndWhileExecuting
3
3
 
4
4
  sidekiq_options queue: :working, unique: :until_and_while_executing
5
5
 
6
- def perform
7
- end
6
+ def perform; end
8
7
  end
@@ -3,6 +3,5 @@ class UntilExecutingJob
3
3
 
4
4
  sidekiq_options queue: :working, unique: :until_executing
5
5
 
6
- def perform
7
- end
6
+ def perform; end
8
7
  end
@@ -0,0 +1,9 @@
1
+ class WithoutArgumentJob
2
+ include Sidekiq::Worker
3
+ sidekiq_options unique: :until_executed,
4
+ log_duplicate_payload: true
5
+
6
+ def perform
7
+ sleep 20
8
+ end
9
+ end
@@ -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', sidekiq_ver: '>= 4.0.0' do
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(schedule uniquejobs:6e47d668ad22db2a3ba0afd331514ce2 uniquejobs)
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', sidekiq_ver: '>= 3.5.3' do
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)