sidekiq-unique-jobs 3.0.14 → 4.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 (99) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +14 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +8 -0
  5. data/.simplecov +12 -0
  6. data/.travis.yml +16 -8
  7. data/Appraisals +10 -10
  8. data/CHANGELOG.md +11 -0
  9. data/Gemfile +11 -1
  10. data/README.md +58 -4
  11. data/Rakefile +2 -1
  12. data/circle.yml +36 -0
  13. data/gemfiles/sidekiq_2.17.gemfile +8 -1
  14. data/gemfiles/sidekiq_3.0.gemfile +8 -1
  15. data/gemfiles/sidekiq_3.1.gemfile +8 -1
  16. data/gemfiles/sidekiq_3.2.gemfile +8 -1
  17. data/gemfiles/sidekiq_3.3.gemfile +8 -1
  18. data/gemfiles/sidekiq_develop.gemfile +8 -1
  19. data/lib/sidekiq-unique-jobs.rb +44 -9
  20. data/lib/sidekiq_unique_jobs/client/middleware.rb +47 -0
  21. data/lib/sidekiq_unique_jobs/config.rb +9 -33
  22. data/lib/sidekiq_unique_jobs/core_ext.rb +46 -0
  23. data/lib/sidekiq_unique_jobs/lock.rb +10 -0
  24. data/lib/sidekiq_unique_jobs/lock/time_calculator.rb +44 -0
  25. data/lib/sidekiq_unique_jobs/lock/until_executed.rb +56 -0
  26. data/lib/sidekiq_unique_jobs/lock/until_executing.rb +6 -0
  27. data/lib/sidekiq_unique_jobs/lock/until_timeout.rb +10 -0
  28. data/lib/sidekiq_unique_jobs/lock/while_executing.rb +31 -0
  29. data/lib/sidekiq_unique_jobs/middleware.rb +30 -14
  30. data/lib/sidekiq_unique_jobs/normalizer.rb +7 -0
  31. data/lib/sidekiq_unique_jobs/options_with_fallback.rb +36 -0
  32. data/lib/sidekiq_unique_jobs/run_lock_failed.rb +1 -0
  33. data/lib/sidekiq_unique_jobs/scripts.rb +50 -0
  34. data/lib/sidekiq_unique_jobs/server/middleware.rb +73 -0
  35. data/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +71 -9
  36. data/lib/sidekiq_unique_jobs/testing.rb +34 -0
  37. data/lib/sidekiq_unique_jobs/testing/sidekiq_overrides.rb +63 -0
  38. data/lib/sidekiq_unique_jobs/unique_args.rb +132 -0
  39. data/lib/sidekiq_unique_jobs/unlockable.rb +26 -0
  40. data/lib/sidekiq_unique_jobs/version.rb +1 -1
  41. data/redis/aquire_lock.lua +9 -0
  42. data/redis/release_lock.lua +14 -0
  43. data/redis/synchronize.lua +15 -0
  44. data/sidekiq-unique-jobs.gemspec +2 -4
  45. data/spec/lib/sidekiq_unique_jobs/client/middleware_spec.rb +195 -0
  46. data/spec/lib/sidekiq_unique_jobs/core_ext_spec.rb +25 -0
  47. data/spec/lib/sidekiq_unique_jobs/lock/time_calculator_spec.rb +81 -0
  48. data/spec/lib/sidekiq_unique_jobs/lock/while_executing_spec.rb +48 -0
  49. data/spec/lib/sidekiq_unique_jobs/normalizer_spec.rb +21 -0
  50. data/spec/lib/sidekiq_unique_jobs/scripts_spec.rb +74 -0
  51. data/spec/lib/sidekiq_unique_jobs/server/middleware_spec.rb +100 -0
  52. data/spec/lib/{sidekiq_testing_enabled_spec.rb → sidekiq_unique_jobs/sidekiq_testing_enabled_spec.rb} +29 -68
  53. data/spec/lib/sidekiq_unique_jobs/sidekiq_unique_ext_spec.rb +79 -0
  54. data/spec/lib/sidekiq_unique_jobs/sidekiq_unique_jobs_spec.rb +36 -0
  55. data/spec/lib/sidekiq_unique_jobs/unique_args_spec.rb +106 -0
  56. data/spec/spec_helper.rb +40 -10
  57. data/spec/support/matchers/redis_matchers.rb +19 -0
  58. data/spec/support/ruby_meta.rb +10 -0
  59. data/spec/support/sidekiq_meta.rb +11 -2
  60. data/spec/support/unique_macros.rb +52 -0
  61. data/spec/workers/after_unlock_worker.rb +13 -0
  62. data/spec/{support → workers}/after_yield_worker.rb +6 -2
  63. data/spec/{support → workers}/another_unique_worker.rb +1 -1
  64. data/spec/workers/before_yield_worker.rb +9 -0
  65. data/spec/workers/expiring_worker.rb +4 -0
  66. data/spec/workers/inline_expiration_worker.rb +8 -0
  67. data/spec/workers/inline_unlock_order_worker.rb +8 -0
  68. data/spec/workers/inline_worker.rb +8 -0
  69. data/spec/workers/just_a_worker.rb +8 -0
  70. data/spec/workers/main_job.rb +8 -0
  71. data/spec/workers/my_unique_worker.rb +8 -0
  72. data/spec/{support → workers}/my_worker.rb +0 -0
  73. data/spec/workers/plain_class.rb +4 -0
  74. data/spec/workers/queue_worker.rb +6 -0
  75. data/spec/workers/queue_worker_with_filter_method.rb +7 -0
  76. data/spec/workers/queue_worker_with_filter_proc.rb +11 -0
  77. data/spec/workers/run_lock_with_retries_worker.rb +12 -0
  78. data/spec/workers/run_lock_worker.rb +7 -0
  79. data/spec/workers/test_class.rb +4 -0
  80. data/spec/workers/unique_job_with_filter_method.rb +18 -0
  81. data/spec/workers/unique_on_all_queues_worker.rb +13 -0
  82. data/spec/{support → workers}/unique_worker.rb +1 -1
  83. data/spec/workers/while_executing_worker.rb +13 -0
  84. metadata +65 -39
  85. data/lib/sidekiq_unique_jobs/connectors.rb +0 -16
  86. data/lib/sidekiq_unique_jobs/connectors/redis_pool.rb +0 -11
  87. data/lib/sidekiq_unique_jobs/connectors/sidekiq_redis.rb +0 -9
  88. data/lib/sidekiq_unique_jobs/connectors/testing.rb +0 -11
  89. data/lib/sidekiq_unique_jobs/inline_testing.rb +0 -12
  90. data/lib/sidekiq_unique_jobs/middleware/client/strategies/testing_inline.rb +0 -25
  91. data/lib/sidekiq_unique_jobs/middleware/client/strategies/unique.rb +0 -105
  92. data/lib/sidekiq_unique_jobs/middleware/client/unique_jobs.rb +0 -43
  93. data/lib/sidekiq_unique_jobs/middleware/server/unique_jobs.rb +0 -69
  94. data/lib/sidekiq_unique_jobs/payload_helper.rb +0 -42
  95. data/lib/sidekiq_unique_jobs/sidekiq_test_overrides.rb +0 -101
  96. data/spec/lib/client_spec.rb +0 -193
  97. data/spec/lib/middleware/server/unique_jobs_spec.rb +0 -112
  98. data/spec/lib/sidekiq_unique_ext_spec.rb +0 -70
  99. data/spec/lib/unlock_order_spec.rb +0 -64
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47d33808dbdda5aed24c7559888c87e9314feda9
4
- data.tar.gz: 7e0698a1ddb3ac9ecff610ec1837e7cbeef6f844
3
+ metadata.gz: 9335a1bcf7592b094855e9d4562840691c9bcc96
4
+ data.tar.gz: bdd063a97f2a10c1844dda8c51b42221b50a52b6
5
5
  SHA512:
6
- metadata.gz: 31028d7ac6a86361d3e32e4946223d0803fa71111e8b4e080947e3a9774a5935e57f5fe9661e63fdbc864ff214c8590548a5e12fce4058f3fad8b68358b2efd0
7
- data.tar.gz: f0a3f8aed7f244ca06067c2753f508e3349dbcd65cce0f7acfdad57d29fbcfafa310b5ff50315a6b3258de39c7e37ffa72dc742924cb7e229f1775492ce6266c
6
+ metadata.gz: 2fd7ce95d41c91ec3155336cf7961e1d6986e92a261e8bde242ed2a720338abff103754c7973cad85d3a29b2f69d13234379877f64b466498ff904d86c6b0729
7
+ data.tar.gz: 7b3488a1eba8ff8b2457d5f70b1253dbdffff3bfca249cee54bf4f6a2673360ea3ce22b573c1297d5ee59959a430f9408e385f9cc4c6bb448966f0b16ef2b3fb
data/.editorconfig ADDED
@@ -0,0 +1,14 @@
1
+ # This file is for unifying the coding style for different editors and IDEs
2
+ # editorconfig.org
3
+
4
+ root = true
5
+
6
+ [*]
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+ indent_style = space
11
+ indent_size = 2
12
+
13
+ [*.md]
14
+ trim_trailing_whitespace = true
data/.gitignore CHANGED
@@ -9,3 +9,5 @@ Gemfile.lock
9
9
  .idea/
10
10
  gemfiles/*.lock
11
11
  *.sw?
12
+ coverage/
13
+ tmp/
data/.rubocop.yml CHANGED
@@ -1,3 +1,11 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/Rakefile'
4
+ - '**/lib'
5
+ - '**/spec'
6
+ Exclude:
7
+ - 'bin/**/*'
8
+ - 'gemfiles/**/*'
1
9
 
2
10
  Lint/HandleExceptions:
3
11
  Enabled: true
data/.simplecov ADDED
@@ -0,0 +1,12 @@
1
+ require 'simplecov-json'
2
+
3
+ SimpleCov.refuse_coverage_drop
4
+ SimpleCov.formatters = [
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ SimpleCov::Formatter::JSONFormatter
7
+ ]
8
+ SimpleCov.start do
9
+ add_filter '/spec/'
10
+ add_filter '/bin/'
11
+ add_filter '/gemfiles/'
12
+ end
data/.travis.yml CHANGED
@@ -1,12 +1,19 @@
1
+ sudo: false
1
2
  language: ruby
3
+ cache: bundler
2
4
  services:
3
5
  - redis-server
6
+ script:
7
+ - if [[ "${STYLE}" = "true" ]]; then bundle exec rubocop; fi;
8
+ - bundle exec rspec spec
4
9
  rvm:
5
10
  - jruby-19mode
6
- - rbx2
11
+ - jruby-9.0.0.0
12
+ - rbx-2
7
13
  - 2.0.0
8
- - 2.1.2
9
- - 2.2.2
14
+ - 2.1.7
15
+ - 2.2.3
16
+ env: STYLE=false
10
17
  gemfile:
11
18
  - gemfiles/sidekiq_develop.gemfile
12
19
  - gemfiles/sidekiq_2.17.gemfile
@@ -14,13 +21,14 @@ gemfile:
14
21
  - gemfiles/sidekiq_3.1.gemfile
15
22
  - gemfiles/sidekiq_3.2.gemfile
16
23
  - gemfiles/sidekiq_3.3.gemfile
17
- branches:
18
- only:
19
- - master
24
+
20
25
  notifications:
21
26
  email:
22
27
  recipients:
23
28
  - mikael@zoolutions.se
24
29
  matrix:
25
- allow_failures:
26
- - rvm: rbx2
30
+ fast_finish: true
31
+ include:
32
+ - rvm: 2.2.3
33
+ gemfile: gemfiles/sidekiq_3.3.gemfile
34
+ env: STYLE=true
data/Appraisals CHANGED
@@ -1,23 +1,23 @@
1
- appraise "sidekiq-develop" do
1
+ appraise 'sidekiq-develop' do
2
2
  gem 'sidekiq', github: 'mperham/sidekiq'
3
3
  end
4
4
 
5
- appraise "sidekiq-2.17" do
5
+ appraise 'sidekiq-2.17' do
6
6
  gem 'sidekiq', '~> 2.17.0'
7
7
  end
8
8
 
9
- appraise "sidekiq-3.0" do
10
- gem "sidekiq", '~> 3.0.0'
9
+ appraise 'sidekiq-3.0' do
10
+ gem 'sidekiq', '~> 3.0.0'
11
11
  end
12
12
 
13
- appraise "sidekiq-3.1" do
14
- gem "sidekiq", '~> 3.1.0'
13
+ appraise 'sidekiq-3.1' do
14
+ gem 'sidekiq', '~> 3.1.0'
15
15
  end
16
16
 
17
- appraise "sidekiq-3.2" do
18
- gem "sidekiq", '~> 3.2.0'
17
+ appraise 'sidekiq-3.2' do
18
+ gem 'sidekiq', '~> 3.2.0'
19
19
  end
20
20
 
21
- appraise "sidekiq-3.3" do
22
- gem "sidekiq", '~> 3.3.0'
21
+ appraise 'sidekiq-3.3' do
22
+ gem 'sidekiq', '~> 3.3.0'
23
23
  end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## v3.0.16 (Unreleased)
2
+
3
+ - Improved uniqueness handling (complete refactoring, upgrade with causion)
4
+ - 100% breaking changes
5
+
6
+ ## v3.0.15
7
+ - Jobs only ever unlock themselves now (see #96 & #94 for info) thanks @pik
8
+ - Slight refactoring and internal renaming. Shouldn't affect anyone
9
+ - Run locks as an alternative when you only need to prevent the same job running twice but want to be able to schedule it multiple times. See #99 (thanks @pik)
10
+ - Fixes #90, #92, #93, #97, #98, #100, #101, #105
11
+
1
12
  ## v3.0.14
2
13
  - Improve uniqueness check performance thanks @mpherham
3
14
  - Remove locks in sidekiq fake testing mode
data/Gemfile CHANGED
@@ -2,4 +2,14 @@ source 'http://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  gem 'appraisal', '~> 2.0.0'
5
- gem 'pry', platform: :mri
5
+
6
+ gem 'rspec-its', require: false
7
+
8
+ platform :mri do
9
+ gem 'pry', require: false
10
+ gem 'pry-rescue', require: false
11
+ gem 'pry-byebug', require: false
12
+ gem 'simplecov-json', require: false
13
+ gem 'memory_profiler', require: false
14
+ gem 'codeclimate-test-reporter', require: false
15
+ end
data/README.md CHANGED
@@ -6,6 +6,13 @@ The missing unique jobs for sidekiq
6
6
 
7
7
  See https://github.com/mperham/sidekiq#requirements for what is required. Starting from 3.0.13 only sidekiq 3 is supported and support for MRI 1.9 is dropped (it might work but won't be worked on)
8
8
 
9
+ Version 4 requires redis 2.6.2!! Don't upgrade to version 4 unless you are on redis 2.6.2.
10
+
11
+ ## Upgrade instructions
12
+
13
+ Easy path - Drop all your unique jobs before upgrading the gem!
14
+ Hard path - See above... Start with a clean slate :)
15
+
9
16
  ## Installation
10
17
 
11
18
  Add this line to your application's Gemfile:
@@ -20,6 +27,34 @@ Or install it yourself as:
20
27
 
21
28
  $ gem install sidekiq-unique-jobs
22
29
 
30
+ ## A word on locking
31
+
32
+ Like @mperham mentions on (this wiki page)[https://github.com/mperham/sidekiq/wiki/Related-Projects#unique-jobs] it is hard to enforce uniqueness with redis in a distributed redis setting.
33
+
34
+ To make things worse there are many ways of wanting to enforce uniqueness.
35
+
36
+ ### While Executing
37
+
38
+ Is to make sure that a job can be scheduled any number of times but only executed a single time per argument provided to the job we call this runtime uniqueness. This is probably most useful forbackground jobs that are fast to execute. (See mhenrixon/sidekiq-unique-jobs#111 for a great example of when this would be right.) While the job is executing/performing no other jobs can be executed at the same time.
39
+
40
+ ### Until Executing
41
+
42
+ This means that a job can only be scheduled into redis once per whatever the configuration of unique arguments. Any jobs added until the first one of the same arguments has been unlocked will just be dropped. This is what was tripping many people up. They would schedule a job to run in the future and it would be impossible to schedule new jobs with those same arguments even immediately. There was some forth and back between also locking jobs on the scheduled queue and the regular queues but in the end I decided it was best to separate these two features out into different locking mechanisms. I think what most people are after is to be able to lock a job while executing or that seems to be what people are most missing at the moment.
43
+
44
+ ### Until Executed
45
+
46
+ This is the combination of the two above. First we lock the job until it executes, then as the job begins executes we keep the lock so that no other jobs with the same arguments can execute at the same time.
47
+
48
+ ### Until Timeout
49
+
50
+ The job won't be unlocked until the timeout/expiry runs out.
51
+
52
+ ### Uniqueness Scope
53
+
54
+ - Queue specific locks
55
+ - Across all queues.
56
+ - Timed / Scheduled jobs
57
+
23
58
  ## Usage
24
59
 
25
60
  All that is required is that you specifically set the sidekiq option for *unique* to true like below:
@@ -33,12 +68,12 @@ should be unique. The job will be unique for the number of seconds configured (d
33
68
  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.
34
69
 
35
70
  *If you want the unique job to stick around even after it has been successfully
36
- processed then just set the unique_unlock_order to anything except `:before_yield` or `:after_yield` (`unique_unlock_order = :never`)
71
+ processed then just set the unique_lock to anything except `:before_yield` or `:after_yield` (`unique_lock = :until_timeout`)
37
72
 
38
73
  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:
39
74
 
40
75
  ```ruby
41
- sidekiq_options unique: true, unique_job_expiration: 120 * 60 # 2 hours
76
+ sidekiq_options unique: true, unique_expiration: 120 * 60 # 2 hours
42
77
  ```
43
78
 
44
79
  Requiring the gem in your gemfile should be sufficient to enable unique jobs.
@@ -96,19 +131,36 @@ Note that objects passed into workers are converted to JSON *after* running thro
96
131
 
97
132
  ### Unlock Ordering
98
133
 
99
- By default the server middleware will release the worker lock after yielding to the next middleware or worker. Alternatively, this can be changed by passing the `unique_unlock_order` option:
134
+ By default the server middleware will release the worker lock after yielding to the next middleware or worker. Alternatively, this can be changed by passing the `unique_lock` option:
100
135
 
101
136
  ```ruby
102
137
  class UniqueJobWithFilterMethod
103
138
  include Sidekiq::Worker
104
139
  sidekiq_options unique: true,
105
- unique_unlock_order: :before_yield
140
+ unique_locks: :until_executing
106
141
 
107
142
  ...
108
143
 
109
144
  end
110
145
  ```
111
146
 
147
+ ### After Unlock Callback
148
+
149
+ If you are using :after_yield as your unlock ordering, Unique Job offers a callback to perform some work after the block is yielded.
150
+
151
+ ```ruby
152
+ class UniqueJobWithFilterMethod
153
+ include Sidekiq::Worker
154
+ sidekiq_options unique: true,
155
+
156
+ def after_unlock
157
+ # block has yielded and lock is released
158
+ end
159
+ ...
160
+ end.
161
+
162
+ ```
163
+
112
164
  ### Unique Storage Method
113
165
 
114
166
  Starting from sidekiq-unique-jobs 3.0.14 we will use the `set` method in a way that has been available since redis 2.6.12. If you are on an older redis version you will have to change a config value like below.
@@ -137,6 +189,8 @@ end
137
189
 
138
190
  ### Testing
139
191
 
192
+ To enable the testing for `sidekiq-unique-jobs`, add `require 'sidekiq_unique_jobs/testing'` to your testing helper.
193
+
140
194
  SidekiqUniqueJobs uses mock_redis for inline testing. Due to complaints about having that as a runtime dependency it was made a development dependency so if you are relying on inline testing you will have to add `gem 'mock_redis'` to your Gemfile.
141
195
 
142
196
  ## Contributing
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env rake
2
+
2
3
  require 'rubygems'
3
4
  require 'bundler/setup'
4
5
  require 'bundler/gem_tasks'
@@ -8,4 +9,4 @@ require 'rubocop/rake_task'
8
9
  RuboCop::RakeTask.new(:style)
9
10
  RSpec::Core::RakeTask.new(:spec)
10
11
 
11
- task default: [:spec, :style]
12
+ task default: [:style, :spec]
data/circle.yml ADDED
@@ -0,0 +1,36 @@
1
+ machine:
2
+ ruby: 2.2.3
3
+ java:
4
+ version: oraclejdk8
5
+ environment:
6
+ JRUBY_OPTS: '-J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -X-C -Xcompile.invokedynamic=false --1.9 -J-Xmx1g'
7
+
8
+ dependencies:
9
+ pre:
10
+ - rvm install jruby-9.0.0.0
11
+ - rvm install jruby-1.7
12
+ - rvm install rbx-2
13
+ - rvm install 2.0.0
14
+ - rvm install 2.1.7
15
+ override:
16
+ - rvm-exec jruby-9.0.0.0 bundle install
17
+ - rvm-exec jruby-1.7 bundle install
18
+ - rvm-exec rbx-2 bundle install
19
+ - rvm-exec 2.0.0 bundle install
20
+ - rvm-exec 2.1.7 bundle install
21
+ - rvm-exec 2.2.3 bundle install
22
+ - rvm-exec jruby-9.0.0.0 bundle exec appraisal install
23
+ - rvm-exec jruby-1.7 bundle exec appraisal install
24
+ - rvm-exec rbx-2 bundle exec appraisal install
25
+ - rvm-exec 2.0.0 bundle exec appraisal install
26
+ - rvm-exec 2.1.7 bundle exec appraisal install
27
+ - rvm-exec 2.2.3 bundle exec appraisal install
28
+
29
+ test:
30
+ override:
31
+ - rvm-exec jruby-9.0.0.0 bundle exec appraisal rspec
32
+ - rvm-exec jruby-1.7 bundle exec appraisal rspec
33
+ - rvm-exec rbx-2 bundle exec appraisal rspec
34
+ - rvm-exec 2.0.0 bundle exec appraisal rspec
35
+ - rvm-exec 2.1.7 bundle exec appraisal rspec
36
+ - rvm-exec 2.2.3 bundle exec appraisal rspec
@@ -3,7 +3,14 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal", "~> 2.0.0"
6
- gem "pry", :platform => :mri
7
6
  gem "sidekiq", "~> 2.17.0"
8
7
 
8
+ platforms :mri do
9
+ gem "pry-suite", :require => false
10
+ gem "let_it_go", :require => false
11
+ gem "memory-profiler", :require => false
12
+ gem "simplecov-json", :require => false
13
+ gem "codeclimate-test-reporter", :require => false
14
+ end
15
+
9
16
  gemspec :path => "../"
@@ -3,7 +3,14 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal", "~> 2.0.0"
6
- gem "pry", :platform => :mri
7
6
  gem "sidekiq", "~> 3.0.0"
8
7
 
8
+ platforms :mri do
9
+ gem "pry-suite", :require => false
10
+ gem "let_it_go", :require => false
11
+ gem "memory-profiler", :require => false
12
+ gem "simplecov-json", :require => false
13
+ gem "codeclimate-test-reporter", :require => false
14
+ end
15
+
9
16
  gemspec :path => "../"
@@ -3,7 +3,14 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal", "~> 2.0.0"
6
- gem "pry", :platform => :mri
7
6
  gem "sidekiq", "~> 3.1.0"
8
7
 
8
+ platforms :mri do
9
+ gem "pry-suite", :require => false
10
+ gem "let_it_go", :require => false
11
+ gem "memory-profiler", :require => false
12
+ gem "simplecov-json", :require => false
13
+ gem "codeclimate-test-reporter", :require => false
14
+ end
15
+
9
16
  gemspec :path => "../"
@@ -3,7 +3,14 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal", "~> 2.0.0"
6
- gem "pry", :platform => :mri
7
6
  gem "sidekiq", "~> 3.2.0"
8
7
 
8
+ platforms :mri do
9
+ gem "pry-suite", :require => false
10
+ gem "let_it_go", :require => false
11
+ gem "memory-profiler", :require => false
12
+ gem "simplecov-json", :require => false
13
+ gem "codeclimate-test-reporter", :require => false
14
+ end
15
+
9
16
  gemspec :path => "../"
@@ -3,7 +3,14 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal", "~> 2.0.0"
6
- gem "pry", :platform => :mri
7
6
  gem "sidekiq", "~> 3.3.0"
8
7
 
8
+ platforms :mri do
9
+ gem "pry-suite", :require => false
10
+ gem "let_it_go", :require => false
11
+ gem "memory-profiler", :require => false
12
+ gem "simplecov-json", :require => false
13
+ gem "codeclimate-test-reporter", :require => false
14
+ end
15
+
9
16
  gemspec :path => "../"
@@ -3,7 +3,14 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal", "~> 2.0.0"
6
- gem "pry", :platform => :mri
7
6
  gem "sidekiq", :github => "mperham/sidekiq"
8
7
 
8
+ platforms :mri do
9
+ gem "pry-suite", :require => false
10
+ gem "let_it_go", :require => false
11
+ gem "memory-profiler", :require => false
12
+ gem "simplecov-json", :require => false
13
+ gem "codeclimate-test-reporter", :require => false
14
+ end
15
+
9
16
  gemspec :path => "../"
@@ -1,9 +1,13 @@
1
- # rubocop:disable FileName
2
- require 'yaml' if RUBY_VERSION.include?('2.0.0')
1
+ require 'yaml' if RUBY_VERSION.include?('2.0.0') # rubocop:disable FileName
2
+ require 'sidekiq_unique_jobs/core_ext'
3
+ require 'sidekiq_unique_jobs/options_with_fallback'
4
+ require 'sidekiq_unique_jobs/scripts'
5
+ require 'sidekiq_unique_jobs/unique_args'
6
+ require 'sidekiq_unique_jobs/unlockable'
7
+ require 'sidekiq_unique_jobs/lock'
3
8
  require 'sidekiq_unique_jobs/middleware'
4
9
  require 'sidekiq_unique_jobs/version'
5
10
  require 'sidekiq_unique_jobs/config'
6
- require 'sidekiq_unique_jobs/payload_helper'
7
11
  require 'sidekiq_unique_jobs/sidekiq_unique_ext'
8
12
 
9
13
  require 'ostruct'
@@ -13,11 +17,11 @@ module SidekiqUniqueJobs
13
17
 
14
18
  def config
15
19
  @config ||= Config.new(
16
- unique_prefix: 'sidekiq_unique',
17
- unique_args_enabled: false,
20
+ unique_prefix: 'uniquejobs',
21
+ unique_args_enabled: true,
18
22
  default_expiration: 30 * 60,
19
- default_unlock_order: :after_yield,
20
- unique_storage_method: :new
23
+ default_lock: :while_executing,
24
+ redis_test_mode: :redis # :mock
21
25
  )
22
26
  end
23
27
 
@@ -25,8 +29,22 @@ module SidekiqUniqueJobs
25
29
  config.unique_args_enabled
26
30
  end
27
31
 
28
- def configure
29
- yield config
32
+ def default_lock
33
+ config.default_lock
34
+ end
35
+
36
+ def configure(options = {})
37
+ if block_given?
38
+ yield config
39
+ else
40
+ options.each do |key, val|
41
+ config[key] = val
42
+ end
43
+ end
44
+ end
45
+
46
+ def namespace
47
+ @namespace ||= Sidekiq.redis { |c| c.respond_to?(:namespace) ? c.namespace : nil }
30
48
  end
31
49
 
32
50
  # Attempt to constantize a string worker_class argument, always
@@ -37,4 +55,21 @@ module SidekiqUniqueJobs
37
55
  rescue NameError
38
56
  worker_class
39
57
  end
58
+
59
+ def redis_version
60
+ @redis_version ||= Sidekiq.redis { |c| c.info('server')['redis_version'] }
61
+ end
62
+
63
+ def connection(redis_pool = nil, &block)
64
+ return mock_redis if config.mocking?
65
+ redis_pool ? redis_pool.with(&block) : Sidekiq.redis(&block)
66
+ end
67
+
68
+ def mock_redis
69
+ @redis_mock ||= MockRedis.new if defined?(MockRedis)
70
+ end
71
+
72
+ def synchronize(item, redis_pool, &blk)
73
+ Lock::WhileExecuting.synchronize(item, redis_pool, &blk)
74
+ end
40
75
  end