sidekiq-unique-jobs 6.0.0.rc3 → 6.0.0.rc4
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/.github/ISSUE_TEMPLATE/bug_report.md +31 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
- data/.gitignore +4 -0
- data/README.md +72 -39
- data/lib/sidekiq_unique_jobs/constants.rb +2 -1
- data/lib/sidekiq_unique_jobs/lock/base_lock.rb +19 -18
- data/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +3 -3
- data/lib/sidekiq_unique_jobs/lock/until_executed.rb +2 -5
- data/lib/sidekiq_unique_jobs/lock/until_executing.rb +2 -3
- data/lib/sidekiq_unique_jobs/lock/until_expired.rb +2 -2
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +5 -8
- data/lib/sidekiq_unique_jobs/lock/while_executing_reject.rb +2 -6
- data/lib/sidekiq_unique_jobs/lock/while_executing_requeue.rb +4 -3
- data/lib/sidekiq_unique_jobs/options_with_fallback.rb +1 -1
- data/lib/sidekiq_unique_jobs/server/middleware.rb +1 -5
- data/lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb +4 -0
- data/lib/sidekiq_unique_jobs/unique_args.rb +2 -3
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17113a3ab2a97217143984d5e401054568eae54dae1bb1e411f5c6c82d8c15c2
|
4
|
+
data.tar.gz: 4a75c98d2174368796e734c11eca12e0f54fbe7fb39c6d55affd2193026acb89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2655eebc021bb239a407739369f18bfe5df559c7182cdd104ce148c4678f5788c24a609d0b9187d2fa6b770408d6002ac5b61460d129f6df5d07dfb96496058c
|
7
|
+
data.tar.gz: 697a789d9e8499cdf2cb74cc8d27d39b9efe36e414eb605f047591fe87710f738ef5d889bdb3ba59c3fd9dcd13261a9463f38c564d32d54e681e596876a904f3
|
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
**Describe the bug**
|
8
|
+
A clear and concise description of what the bug is.
|
9
|
+
|
10
|
+
**Expected behavior**
|
11
|
+
A clear and concise description of what you expected to happen.
|
12
|
+
|
13
|
+
**Current behavior**
|
14
|
+
What happens instead of the expected behavior?
|
15
|
+
|
16
|
+
**Worker class**
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
class MyWorker
|
20
|
+
include Sidekiq::Worker
|
21
|
+
sidekiq_options unique: :until_executed, queue: :undefault
|
22
|
+
def perform(args); end
|
23
|
+
|
24
|
+
def self.unique_args(args)
|
25
|
+
# the way you consider unique arguments
|
26
|
+
end
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
**Additional context**
|
31
|
+
Add any other context about the problem here.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
**Is your feature request related to a problem? Please describe.**
|
8
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
9
|
+
|
10
|
+
**Describe the solution you'd like**
|
11
|
+
A clear and concise description of what you want to happen.
|
12
|
+
|
13
|
+
**Describe alternatives you've considered**
|
14
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
15
|
+
|
16
|
+
**Additional context**
|
17
|
+
Add any other context or screenshots about the feature request here.
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,27 +2,20 @@
|
|
2
2
|
|
3
3
|
The missing unique jobs for sidekiq
|
4
4
|
|
5
|
-
|
5
|
+
## Documentation
|
6
6
|
|
7
|
-
This is the documentation for the master branch. You can find the documentation for each release by navigating to its tag: https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v5.0.10.
|
7
|
+
This is the documentation for the master branch. You can find the documentation for each release by navigating to its tag: https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v5.0.10.
|
8
8
|
|
9
9
|
Below are links to the latest major versions (4 & 5):
|
10
|
+
|
10
11
|
- [v5.0.10](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v5.0.10)
|
11
12
|
- [v4.0.18](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v4.0.18)
|
12
13
|
|
13
14
|
## Requirements
|
14
15
|
|
15
|
-
See https://github.com/mperham/sidekiq#requirements for what is required. Starting from 5.0.0 only sidekiq >= 4 is supported and support for MRI <=
|
16
|
-
|
17
|
-
Version 5 requires redis >= 3
|
18
|
-
|
19
|
-
### ActiveJob
|
16
|
+
See https://github.com/mperham/sidekiq#requirements for what is required. Starting from 5.0.0 only sidekiq >= 4 is supported and support for MRI <= 2.1 is dropped. ActiveJob is not supported
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
If you are in this position and you can't figure it out; I have done such migrations for really big clients before. I am a consultant with a ton of experience on such jobs. My rate is fair and I am easy to get along with.
|
24
|
-
|
25
|
-
If that is not an option I apologize. This gem won't support ActiveJob moving forward. It would require monkey patching too much.
|
18
|
+
Version 6 requires Redis >= 3 and pure Sidekiq, no ActiveJob supported anymore. See [About ActiveJob](https://github.com/mhenrixon/sidekiq-unique-jobs/wiki/About-ActiveJob) for why.
|
26
19
|
|
27
20
|
## Installation
|
28
21
|
|
@@ -38,15 +31,17 @@ Or install it yourself as:
|
|
38
31
|
|
39
32
|
$ gem install sidekiq-unique-jobs
|
40
33
|
|
41
|
-
##
|
34
|
+
## General Information
|
35
|
+
|
36
|
+
See [Interaction w/ Sidekiq](https://github.com/mhenrixon/sidekiq-unique-jobs/wiki/How-this-gem-interacts-with-Sidekiq) on how the gem interacts with Sidekiq.
|
42
37
|
|
43
|
-
|
38
|
+
See [Locking & Unlocking](https://github.com/mhenrixon/sidekiq-unique-jobs/wiki/Locking-&-Unlocking) for an overview of the differences on when the various lock types are locked and unlocked.
|
44
39
|
|
45
40
|
### Options
|
46
41
|
|
47
42
|
#### Lock Expiration
|
48
43
|
|
49
|
-
This is probably not the configuration option you want...
|
44
|
+
This is probably not the configuration option you want...
|
50
45
|
|
51
46
|
Since the client and the server are disconnected and not running inside the same process, setting a lock expiration is probably not what you want. Any keys that are used by this gem WILL be removed at the time of the expiration. For jobs that are scheduled in the future the key will expire when that job is scheduled + whatever expiration you have set.
|
52
47
|
|
@@ -67,7 +62,54 @@ sidekiq_options lock_timeout: 5 # wait 5 seconds
|
|
67
62
|
sidekiq_options lock_timeout: nil # lock indefinitely, this process won't continue until it gets a lock. VERY DANGEROUS!!
|
68
63
|
```
|
69
64
|
|
70
|
-
####
|
65
|
+
#### Unique Across Queues
|
66
|
+
|
67
|
+
This configuration option is slightly misleading. It doesn't disregard the queue on other jobs. Just on itself, this means that a worker that might schedule jobs into multiple queues will be able to have uniqueness enforced on all queues it is pushed to.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
class Worker
|
71
|
+
include Sidekiq::Worker
|
72
|
+
|
73
|
+
sidekiq_options: unique_across_queues: true, queue: 'default'
|
74
|
+
|
75
|
+
def perform(args); end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
Now if you push override the queue with `Worker.set(queue: 'another').perform_async(1)` it will still be considered unique when compared to `Worker.perform_async(1)` (that was actually pushed to the queue `default`).
|
80
|
+
|
81
|
+
#### Unique Across Workers
|
82
|
+
|
83
|
+
This configuration option is slightly misleading. It doesn't disregard the worker class on other jobs. Just on itself, this means that a worker that the worker class won't be used for generating the unique digest. The only way this option really makes sense is when you want to have uniqueness between two different worker classes.
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
class WorkerOne
|
87
|
+
include Sidekiq::Worker
|
88
|
+
|
89
|
+
sidekiq_options: unique_across_workers: true, queue: 'default'
|
90
|
+
|
91
|
+
def perform(args); end
|
92
|
+
end
|
93
|
+
|
94
|
+
class WorkerTwo
|
95
|
+
include Sidekiq::Worker
|
96
|
+
|
97
|
+
sidekiq_options: unique_across_workers: true, queue: 'default'
|
98
|
+
|
99
|
+
def perform(args); end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
WorkerOne.perform_async(1)
|
104
|
+
# => 'the jobs unique id'
|
105
|
+
|
106
|
+
WorkerTwo.perform_async(1)
|
107
|
+
# => nil because WorkerOne just stole the lock
|
108
|
+
```
|
109
|
+
|
110
|
+
### Locks
|
111
|
+
|
112
|
+
####
|
71
113
|
|
72
114
|
### Until Executing
|
73
115
|
|
@@ -83,14 +125,13 @@ sidekiq_options unique: :until_executing
|
|
83
125
|
|
84
126
|
Locks from when the client pushes the job to the queue. Will be unlocked when the server has successfully processed the job.
|
85
127
|
|
86
|
-
|
87
128
|
```ruby
|
88
129
|
sidekiq_options unique: :until_executed
|
89
130
|
```
|
90
131
|
|
91
132
|
### Until Timeout
|
92
133
|
|
93
|
-
Locks from when the client pushes the job to the queue. Will be unlocked when the specified timeout has been reached.
|
134
|
+
Locks from when the client pushes the job to the queue. Will be unlocked when the specified timeout has been reached.
|
94
135
|
|
95
136
|
```ruby
|
96
137
|
sidekiq_options unique: :until_expired
|
@@ -106,11 +147,9 @@ sidekiq_options unique: :until_and_while_executing
|
|
106
147
|
|
107
148
|
### While Executing
|
108
149
|
|
109
|
-
With this lock type it is possible to put any number of these jobs on the queue, but as the server pops the job from the queue it will create a lock and then wait until other locks are done processing. It
|
150
|
+
With this lock type it is possible to put any number of these jobs on the queue, but as the server pops the job from the queue it will create a lock and then wait until other locks are done processing. It _looks_ like multiple jobs are running at the same time but in fact the second job will only be waiting for the first job to finish.
|
110
151
|
|
111
|
-
|
112
|
-
|
113
|
-
Unless this job is configured with a `lock_timeout: nil` or `lock_timeout: > 0` then all jobs that are attempted to be executed will just be dropped without waiting.
|
152
|
+
**NOTE** Unless this job is configured with a `lock_timeout: nil` or `lock_timeout: > 0` then all jobs that are attempted to be executed will just be dropped without waiting.
|
114
153
|
|
115
154
|
```ruby
|
116
155
|
sidekiq_options unique: :while_executing, lock_timeout: nil
|
@@ -135,17 +174,9 @@ In the console you should see something like:
|
|
135
174
|
10:33:04 worker.1 | 2017-04-23T08:33:04.973Z 84404 TID-ougq8cs8s WhileExecutingWorker JID-9e197460c067b22eb1b5d07f INFO: done: 40.014 sec
|
136
175
|
```
|
137
176
|
|
138
|
-
|
139
|
-
### Uniqueness Scope
|
140
|
-
|
141
|
-
- Queue specific locks
|
142
|
-
- Across all queues - [examples/unique_on_all_queues_job.rb](https://github.com/mhenrixon/sidekiq-unique-jobs/blob/master/examples/unique_on_all_queues_job.rb)
|
143
|
-
- Across all workers - [examples/unique_across_workers_job.rb](https://github.com/mhenrixon/sidekiq-unique-jobs/blob/master/examples/unique_across_workers_job.rb)
|
144
|
-
- Timed / Scheduled jobs
|
145
|
-
|
146
177
|
## Usage
|
147
178
|
|
148
|
-
All that is required is that you specifically set the sidekiq option for
|
179
|
+
All that is required is that you specifically set the sidekiq option for _unique_ to a valid value like below:
|
149
180
|
|
150
181
|
```ruby
|
151
182
|
sidekiq_options unique: :while_executing
|
@@ -165,7 +196,7 @@ The method or the proc can return a modified version of args without the transie
|
|
165
196
|
class UniqueJobWithFilterMethod
|
166
197
|
include Sidekiq::Worker
|
167
198
|
sidekiq_options unique: :until_and_while_executing,
|
168
|
-
unique_args: :unique_args
|
199
|
+
unique_args: :unique_args # this is default and will be used if such a method is defined
|
169
200
|
|
170
201
|
def self.unique_args(args)
|
171
202
|
[ args[0], args[2][:type] ]
|
@@ -185,9 +216,6 @@ class UniqueJobWithFilterProc
|
|
185
216
|
end
|
186
217
|
```
|
187
218
|
|
188
|
-
The previous problems with unique args being string in server and symbol in client is no longer a problem because the `UniqueArgs` class accounts for this and converts everything to json now. If you find an edge case please provide and example so that we can add coverage and fix it.
|
189
|
-
|
190
|
-
|
191
219
|
It is also quite possible to ensure different types of unique args based on context. I can't vouch for the below example but see [#203](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/203) for the discussion.
|
192
220
|
|
193
221
|
```ruby
|
@@ -207,10 +235,12 @@ class UniqueJobWithFilterMethod
|
|
207
235
|
end
|
208
236
|
```
|
209
237
|
|
210
|
-
|
211
238
|
### After Unlock Callback
|
212
239
|
|
213
|
-
If you
|
240
|
+
If you need to perform any additional work after the lock has been released you can provide an `#after_unlock` instance method. The method will be called when the lock has been unlocked. Most times this means after yield but there are two exceptions to that.
|
241
|
+
|
242
|
+
**Exception 1:** UntilExecuting unlocks and calls back before yielding.
|
243
|
+
**Exception 2:** UntilExpired expires eventually, no after_unlock hook is called.
|
214
244
|
|
215
245
|
```ruby
|
216
246
|
class UniqueJobWithFilterMethod
|
@@ -222,12 +252,11 @@ class UniqueJobWithFilterMethod
|
|
222
252
|
end
|
223
253
|
...
|
224
254
|
end.
|
225
|
-
|
226
255
|
```
|
227
256
|
|
228
257
|
### Logging
|
229
258
|
|
230
|
-
To see logging in sidekiq when duplicate payload has been filtered out you can enable on a per worker basis using the sidekiq options.
|
259
|
+
To see logging in sidekiq when duplicate payload has been filtered out you can enable on a per worker basis using the sidekiq options. The default value is false
|
231
260
|
|
232
261
|
```ruby
|
233
262
|
class UniqueJobWithFilterMethod
|
@@ -241,15 +270,19 @@ end
|
|
241
270
|
```
|
242
271
|
|
243
272
|
## Debugging
|
273
|
+
|
244
274
|
There are two ways to display and remove keys regarding uniqueness. The console way and the command line way.
|
245
275
|
|
246
276
|
### Console
|
277
|
+
|
247
278
|
Start the console with the following command `bundle exec jobs console`.
|
248
279
|
|
249
280
|
#### List Unique Keys
|
281
|
+
|
250
282
|
`keys '*', 100`
|
251
283
|
|
252
284
|
#### Remove Unique Keys
|
285
|
+
|
253
286
|
`del '*', 100, false` the dry_run and count parameters are both required. This is to have some type of protection against clearing out all uniqueness.
|
254
287
|
|
255
288
|
### Command Line
|
@@ -9,10 +9,11 @@ module SidekiqUniqueJobs
|
|
9
9
|
LOCK_TIMEOUT_KEY ||= 'lock_timeout'
|
10
10
|
LOG_DUPLICATE_KEY ||= 'log_duplicate_payload'
|
11
11
|
QUEUE_KEY ||= 'queue'
|
12
|
+
UNIQUE_ACROSS_QUEUES_KEY ||= 'unique_across_queues'
|
12
13
|
UNIQUE_ACROSS_WORKERS_KEY ||= 'unique_across_workers'
|
13
14
|
UNIQUE_ARGS_KEY ||= 'unique_args'
|
14
15
|
UNIQUE_DIGEST_KEY ||= 'unique_digest'
|
15
16
|
UNIQUE_KEY ||= 'unique'
|
16
|
-
UNIQUE_ON_ALL_QUEUES_KEY ||= 'unique_on_all_queues'
|
17
|
+
UNIQUE_ON_ALL_QUEUES_KEY ||= 'unique_on_all_queues' # TODO: Remove in v6.1
|
17
18
|
UNIQUE_PREFIX_KEY ||= 'unique_prefix'
|
18
19
|
end
|
@@ -5,16 +5,18 @@ module SidekiqUniqueJobs
|
|
5
5
|
class BaseLock
|
6
6
|
include SidekiqUniqueJobs::Logging
|
7
7
|
|
8
|
-
def initialize(item, redis_pool = nil)
|
8
|
+
def initialize(item, callback, redis_pool = nil)
|
9
9
|
@item = prepare_item(item)
|
10
|
+
@callback = callback
|
10
11
|
@redis_pool = redis_pool
|
12
|
+
@operative = true
|
11
13
|
end
|
12
14
|
|
13
15
|
def lock
|
14
16
|
locksmith.lock(item[LOCK_TIMEOUT_KEY])
|
15
17
|
end
|
16
18
|
|
17
|
-
def execute
|
19
|
+
def execute
|
18
20
|
raise NotImplementedError, "##{__method__} needs to be implemented in #{self.class}"
|
19
21
|
end
|
20
22
|
|
@@ -36,20 +38,19 @@ module SidekiqUniqueJobs
|
|
36
38
|
|
37
39
|
private
|
38
40
|
|
39
|
-
attr_reader :item, :redis_pool, :operative
|
41
|
+
attr_reader :item, :redis_pool, :operative, :callback
|
40
42
|
|
41
43
|
def locksmith
|
42
44
|
@locksmith ||= SidekiqUniqueJobs::Locksmith.new(item, redis_pool)
|
43
45
|
end
|
44
46
|
|
45
|
-
def
|
46
|
-
@operative = true
|
47
|
+
def with_cleanup
|
47
48
|
yield
|
48
49
|
rescue Sidekiq::Shutdown
|
49
50
|
@operative = false
|
50
51
|
raise
|
51
52
|
ensure
|
52
|
-
|
53
|
+
unlock_with_callback
|
53
54
|
end
|
54
55
|
|
55
56
|
def prepare_item(item)
|
@@ -60,23 +61,23 @@ module SidekiqUniqueJobs
|
|
60
61
|
item
|
61
62
|
end
|
62
63
|
|
63
|
-
def unlock_and_callback(callback)
|
64
|
-
return notify_about_manual_unlock unless operative
|
65
|
-
unlock
|
66
|
-
delete
|
67
|
-
|
68
|
-
return notify_about_manual_unlock if locked?
|
69
|
-
callback_safely(callback)
|
70
|
-
end
|
71
|
-
|
72
64
|
def notify_about_manual_unlock
|
73
65
|
log_fatal("the unique_key: #{item[UNIQUE_DIGEST_KEY]} needs to be unlocked manually")
|
66
|
+
false
|
67
|
+
end
|
68
|
+
|
69
|
+
def unlock_with_callback
|
70
|
+
return notify_about_manual_unlock unless operative
|
71
|
+
return notify_about_manual_unlock unless unlock
|
72
|
+
|
73
|
+
callback_safely
|
74
|
+
item[JID_KEY]
|
74
75
|
end
|
75
76
|
|
76
|
-
def callback_safely
|
77
|
-
callback
|
77
|
+
def callback_safely
|
78
|
+
callback&.call
|
78
79
|
rescue StandardError
|
79
|
-
log_warn("
|
80
|
+
log_warn("The lock for #{item[UNIQUE_DIGEST_KEY]} has been released but the #after_unlock callback failed!")
|
80
81
|
raise
|
81
82
|
end
|
82
83
|
end
|
@@ -3,17 +3,17 @@
|
|
3
3
|
module SidekiqUniqueJobs
|
4
4
|
class Lock
|
5
5
|
class UntilAndWhileExecuting < BaseLock
|
6
|
-
def execute
|
6
|
+
def execute
|
7
7
|
return unless locked?
|
8
8
|
unlock
|
9
9
|
|
10
|
-
runtime_lock.execute
|
10
|
+
runtime_lock.execute do
|
11
11
|
yield if block_given?
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def runtime_lock
|
16
|
-
@runtime_lock ||= SidekiqUniqueJobs::Lock::WhileExecuting.new(item, redis_pool)
|
16
|
+
@runtime_lock ||= SidekiqUniqueJobs::Lock::WhileExecuting.new(item, callback, redis_pool)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -5,12 +5,9 @@ module SidekiqUniqueJobs
|
|
5
5
|
class UntilExecuted < BaseLock
|
6
6
|
OK ||= 'OK'
|
7
7
|
|
8
|
-
def execute
|
8
|
+
def execute
|
9
9
|
return unless locked?
|
10
|
-
|
11
|
-
yield if block_given?
|
12
|
-
end
|
13
|
-
unlock
|
10
|
+
with_cleanup { yield if block_given? }
|
14
11
|
end
|
15
12
|
end
|
16
13
|
end
|
@@ -5,8 +5,8 @@ module SidekiqUniqueJobs
|
|
5
5
|
class WhileExecuting < BaseLock
|
6
6
|
RUN_SUFFIX ||= ':RUN'
|
7
7
|
|
8
|
-
def initialize(item, redis_pool = nil)
|
9
|
-
super(item, redis_pool)
|
8
|
+
def initialize(item, callback, redis_pool = nil)
|
9
|
+
super(item, callback, redis_pool)
|
10
10
|
append_unique_key_suffix
|
11
11
|
end
|
12
12
|
|
@@ -17,12 +17,9 @@ module SidekiqUniqueJobs
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# Locks the job with the RUN_SUFFIX appended
|
20
|
-
def execute
|
21
|
-
locksmith.lock(item[LOCK_TIMEOUT_KEY])
|
22
|
-
|
23
|
-
yield if block_given?
|
24
|
-
end
|
25
|
-
end
|
20
|
+
def execute
|
21
|
+
return unless locksmith.lock(item[LOCK_TIMEOUT_KEY])
|
22
|
+
with_cleanup { yield if block_given? }
|
26
23
|
end
|
27
24
|
|
28
25
|
private
|
@@ -3,14 +3,10 @@
|
|
3
3
|
module SidekiqUniqueJobs
|
4
4
|
class Lock
|
5
5
|
class WhileExecutingReject < WhileExecuting
|
6
|
-
def execute
|
6
|
+
def execute
|
7
7
|
return reject unless locksmith.lock(item[LOCK_TIMEOUT_KEY])
|
8
8
|
|
9
|
-
|
10
|
-
yield if block_given?
|
11
|
-
end
|
12
|
-
|
13
|
-
unlock
|
9
|
+
with_cleanup { yield if block_given? }
|
14
10
|
end
|
15
11
|
|
16
12
|
# Private below here, keeping public due to testing reasons
|
@@ -7,12 +7,13 @@ module SidekiqUniqueJobs
|
|
7
7
|
true
|
8
8
|
end
|
9
9
|
|
10
|
-
def execute
|
10
|
+
def execute
|
11
11
|
locksmith.lock(item[LOCK_TIMEOUT_KEY], raise: true) do
|
12
|
-
yield
|
13
|
-
callback.call
|
12
|
+
yield if block_given?
|
14
13
|
end
|
15
14
|
|
15
|
+
unlock
|
16
|
+
|
16
17
|
Sidekiq::Client.push(item) unless locksmith.locked?
|
17
18
|
end
|
18
19
|
end
|
@@ -11,7 +11,7 @@ module SidekiqUniqueJobs
|
|
11
11
|
@queue = queue
|
12
12
|
return yield if unique_disabled?
|
13
13
|
|
14
|
-
lock.execute
|
14
|
+
lock.execute do
|
15
15
|
yield
|
16
16
|
end
|
17
17
|
end
|
@@ -19,10 +19,6 @@ module SidekiqUniqueJobs
|
|
19
19
|
protected
|
20
20
|
|
21
21
|
attr_reader :item
|
22
|
-
|
23
|
-
def after_unlock_hook
|
24
|
-
-> { worker_class.after_unlock if worker_method_defined?(:after_unlock) }
|
25
|
-
end
|
26
22
|
end
|
27
23
|
end
|
28
24
|
end
|
@@ -19,6 +19,10 @@ module SidekiqUniqueJobs
|
|
19
19
|
@_worker_class ||= worker_class_constantize # rubocop:disable Naming/MemoizedInstanceVariableName
|
20
20
|
end
|
21
21
|
|
22
|
+
def after_unlock_hook
|
23
|
+
-> { worker_class.after_unlock if worker_method_defined?(:after_unlock) }
|
24
|
+
end
|
25
|
+
|
22
26
|
# Attempt to constantize a string worker_class argument, always
|
23
27
|
# failing back to the original argument when the constant can't be found
|
24
28
|
#
|
@@ -6,8 +6,6 @@ require 'sidekiq_unique_jobs/normalizer'
|
|
6
6
|
module SidekiqUniqueJobs
|
7
7
|
# This class exists to be testable and the entire api should be considered private
|
8
8
|
class UniqueArgs
|
9
|
-
CLASS_NAME = 'SidekiqUniqueJobs::UniqueArgs'
|
10
|
-
|
11
9
|
include SidekiqUniqueJobs::Logging
|
12
10
|
include SidekiqUniqueJobs::SidekiqWorkerMethods
|
13
11
|
|
@@ -56,7 +54,8 @@ module SidekiqUniqueJobs
|
|
56
54
|
end
|
57
55
|
|
58
56
|
def unique_on_all_queues?
|
59
|
-
item[
|
57
|
+
item[UNIQUE_ACROSS_QUEUES_KEY] || worker_options[UNIQUE_ACROSS_QUEUES_KEY] ||
|
58
|
+
item[UNIQUE_ON_ALL_QUEUES_KEY] || worker_options[UNIQUE_ON_ALL_QUEUES_KEY] # TODO: Remove in v 6.1
|
60
59
|
end
|
61
60
|
|
62
61
|
def unique_across_workers?
|
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: 6.0.0.
|
4
|
+
version: 6.0.0.rc4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Henriksson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -177,6 +177,8 @@ files:
|
|
177
177
|
- ".eslintignore"
|
178
178
|
- ".eslintrc"
|
179
179
|
- ".fasterer.yml"
|
180
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
181
|
+
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
180
182
|
- ".gitignore"
|
181
183
|
- ".reek"
|
182
184
|
- ".rspec"
|