sidekiq-unique-jobs 7.1.14 → 7.1.17
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/CHANGELOG.md +46 -0
- data/README.md +8 -9
- data/lib/sidekiq_unique_jobs/lock/until_executed.rb +5 -1
- data/lib/sidekiq_unique_jobs/lock/until_expired.rb +3 -1
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +4 -1
- data/lib/sidekiq_unique_jobs/lock_args.rb +1 -1
- data/lib/sidekiq_unique_jobs/lock_config.rb +2 -2
- data/lib/sidekiq_unique_jobs/lock_digest.rb +2 -2
- data/lib/sidekiq_unique_jobs/locksmith.rb +1 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_common.lua +1 -1
- data/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb +1 -1
- data/lib/sidekiq_unique_jobs/orphans/manager.rb +9 -3
- data/lib/sidekiq_unique_jobs/orphans/ruby_reaper.rb +21 -0
- data/lib/sidekiq_unique_jobs/testing.rb +22 -8
- data/lib/sidekiq_unique_jobs/timer_task.rb +61 -55
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 787e3a8e85324b12df2f67dc04bee3ad3ad26deadc06ce170c9a5c5be62c1047
|
4
|
+
data.tar.gz: d280fac7bf32f98bbe8071822463c7184e24339ad756953131d113f2b18710a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6549578ab2200965dcbab5e8acbf9e159f5dccce5bd2eb277b6914739e3279195169fd59349d47ae8c2cf9dec2bb7b2116fbceafd17d442b1be6096f9e559fb
|
7
|
+
data.tar.gz: e2469b5c19d39d97fb231db49f291a8e5dcd6763f39c28d794b69b43f1551ffc5275075b39a6d11a5eda82409f87f3d4a0d5d0ce2789b4cf90f84c5940c58c2c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,51 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v7.1.16](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.16) (2022-04-02)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.15...v7.1.16)
|
6
|
+
|
7
|
+
**Implemented enhancements:**
|
8
|
+
|
9
|
+
- Abort Ruby Reaper when sidekiq queues are full [\#690](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/690) ([francesmcmullin](https://github.com/francesmcmullin))
|
10
|
+
- Quote '3.0' to ensure CI uses Ruby 3.0.x for the 3.0 entry [\#689](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/689) ([petergoldstein](https://github.com/petergoldstein))
|
11
|
+
|
12
|
+
**Fixed bugs:**
|
13
|
+
|
14
|
+
- Hotfix: Ensure consistent lock args [\#699](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/699) ([mhenrixon](https://github.com/mhenrixon))
|
15
|
+
- Expire older changelog entries first [\#698](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/698) ([mhenrixon](https://github.com/mhenrixon))
|
16
|
+
- Fix drift [\#688](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/688) ([mhenrixon](https://github.com/mhenrixon))
|
17
|
+
|
18
|
+
**Closed issues:**
|
19
|
+
|
20
|
+
- concurrent-ruby has dropped support for TimerTask timeouts [\#697](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/697)
|
21
|
+
- Most recent changelogs are removed first [\#696](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/696)
|
22
|
+
- Improve README slightly [\#694](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/694)
|
23
|
+
- locksmith.rb:327: NoMethodError: undefined method `+' for nil:NilClass [\#686](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/686)
|
24
|
+
- lock\_timeout cannot be nil [\#675](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/675)
|
25
|
+
- Skip reaping when queues are too large [\#670](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/670)
|
26
|
+
|
27
|
+
**Merged pull requests:**
|
28
|
+
|
29
|
+
- Improve readme [\#695](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/695) ([fwolfst](https://github.com/fwolfst))
|
30
|
+
- Add funding\_uri to gemspec [\#693](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/693) ([fwolfst](https://github.com/fwolfst))
|
31
|
+
- Fix worker validator [\#685](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/685) ([victorfgs](https://github.com/victorfgs))
|
32
|
+
|
33
|
+
## [v7.1.15](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.15) (2022-02-10)
|
34
|
+
|
35
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.14...v7.1.15)
|
36
|
+
|
37
|
+
**Merged pull requests:**
|
38
|
+
|
39
|
+
- Fixing reschedule when using a non default queue [\#679](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/679) ([bigzed](https://github.com/bigzed))
|
40
|
+
|
41
|
+
## [v7.1.14](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.14) (2022-02-04)
|
42
|
+
|
43
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.13...v7.1.14)
|
44
|
+
|
45
|
+
**Implemented enhancements:**
|
46
|
+
|
47
|
+
- Fix the remaining deprecation warnings [\#681](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/681) ([mhenrixon](https://github.com/mhenrixon))
|
48
|
+
|
3
49
|
## [v7.1.13](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.13) (2022-02-03)
|
4
50
|
|
5
51
|
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.12...v7.1.13)
|
data/README.md
CHANGED
@@ -90,7 +90,7 @@ Want to show me some ❤️ for the hard work I do on this gem? You can use the
|
|
90
90
|
|
91
91
|
This gem adds unique constraints to sidekiq jobs. The uniqueness is achieved by creating a set of keys in redis based off of `queue`, `class`, `args` (in the sidekiq job hash).
|
92
92
|
|
93
|
-
By default, only one lock for a given hash can be acquired. What happens when a lock can't be acquired is governed by a chosen [Conflict Strategy](#conflict-strategy) strategy. Unless a conflict strategy is chosen
|
93
|
+
By default, only one lock for a given hash can be acquired. What happens when a lock can't be acquired is governed by a chosen [Conflict Strategy](#conflict-strategy) strategy. Unless a conflict strategy is chosen (?)
|
94
94
|
|
95
95
|
This is the documentation for the `main` branch. You can find the documentation for each release by navigating to its tag.
|
96
96
|
|
@@ -151,7 +151,7 @@ end
|
|
151
151
|
|
152
152
|
### Your first worker
|
153
153
|
|
154
|
-
The most likely to be
|
154
|
+
The lock type most likely to be is `:until_executed`. This type of lock creates a lock from when `UntilExecutedWorker.perform_async` is called until right after `UntilExecutedWorker.new.perform` has been called.
|
155
155
|
|
156
156
|
```ruby
|
157
157
|
# frozen_string_literal: true
|
@@ -159,8 +159,7 @@ The most likely to be used worker is `:until_executed`. This type of lock create
|
|
159
159
|
class UntilExecutedWorker
|
160
160
|
include Sidekiq::Worker
|
161
161
|
|
162
|
-
sidekiq_options
|
163
|
-
lock: :until_executed
|
162
|
+
sidekiq_options lock: :until_executed
|
164
163
|
|
165
164
|
def perform
|
166
165
|
logger.info("cowboy")
|
@@ -346,9 +345,9 @@ Please not that if you try to override a default lock, an `ArgumentError` will b
|
|
346
345
|
|
347
346
|
## Conflict Strategy
|
348
347
|
|
349
|
-
Decides how we handle conflict. We can either reject the job to the dead queue or reschedule it. Both are useful for jobs that absolutely need to run and have been configured to use the lock `WhileExecuting` that is used only by the sidekiq server process.
|
348
|
+
Decides how we handle conflict. We can either `reject` the job to the dead queue or `reschedule` it. Both are useful for jobs that absolutely need to run and have been configured to use the lock `WhileExecuting` that is used only by the sidekiq server process.
|
350
349
|
|
351
|
-
|
350
|
+
Furthermore, `log` can be be used with the lock `UntilExecuted` and `UntilExpired`. Now we write a log entry saying the job could not be pushed because it is a duplicate of another job with the same arguments.
|
352
351
|
|
353
352
|
It is possible for locks to have different conflict strategy for the client and server. This is useful for `:until_and_while_executing`.
|
354
353
|
|
@@ -394,7 +393,7 @@ queue and retry the lock again.
|
|
394
393
|
This is slightly dangerous and should probably only be used for jobs that are
|
395
394
|
always scheduled in the future. Currently only attempting to retry one time.
|
396
395
|
|
397
|
-
###
|
396
|
+
### reschedule
|
398
397
|
|
399
398
|
```ruby
|
400
399
|
sidekiq_options on_conflict: :reschedule
|
@@ -568,7 +567,7 @@ The reason this happens is that the server couldn't find a valid sidekiq worker
|
|
568
567
|
|
569
568
|
### Validating Worker Configuration
|
570
569
|
|
571
|
-
Since v7 it is possible to perform some simple validation against your workers sidekiq_options
|
570
|
+
Since v7 it is possible to perform some simple validation against your workers `sidekiq_options`. What it does is scan for some issues that are known to cause problems in production.
|
572
571
|
|
573
572
|
Let's take a _bad_ worker:
|
574
573
|
|
@@ -604,7 +603,7 @@ assert_raise(InvalidWorker){ SidekiqUniqueJobs.validate_worker!(BadWorker.get_si
|
|
604
603
|
|
605
604
|
### Uniqueness
|
606
605
|
|
607
|
-
This has been probably the most confusing part of this gem. People get really confused with how unreliable the unique jobs have been. I there for decided to do what Mike is doing for sidekiq enterprise. Read the section about unique jobs: [Enterprise unique jobs][]
|
606
|
+
This has been probably the most confusing part of this gem. People get really confused with how unreliable the unique jobs have been. I there for decided to do what Mike is doing for sidekiq enterprise. Read the section about unique jobs: [Enterprise unique jobs][](?)
|
608
607
|
|
609
608
|
```ruby
|
610
609
|
SidekiqUniqueJobs.configure do |config|
|
@@ -33,10 +33,14 @@ module SidekiqUniqueJobs
|
|
33
33
|
# Executes in the Sidekiq server process
|
34
34
|
# @yield to the worker class perform method
|
35
35
|
def execute
|
36
|
-
locksmith.execute do
|
36
|
+
executed = locksmith.execute do
|
37
37
|
yield
|
38
38
|
unlock_and_callback
|
39
39
|
end
|
40
|
+
|
41
|
+
reflect(:execution_failed, item) unless executed
|
42
|
+
|
43
|
+
nil
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
@@ -33,7 +33,9 @@ module SidekiqUniqueJobs
|
|
33
33
|
# Executes in the Sidekiq server process
|
34
34
|
# @yield to the worker class perform method
|
35
35
|
def execute(&block)
|
36
|
-
locksmith.execute(&block)
|
36
|
+
executed = locksmith.execute(&block)
|
37
|
+
|
38
|
+
reflect(:execution_failed, item) unless executed
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
@@ -34,7 +34,7 @@ module SidekiqUniqueJobs
|
|
34
34
|
# The unique arguments to use for creating a lock
|
35
35
|
# @return [Array] the arguments filters by the {#filtered_args} method if {#lock_args_enabled?}
|
36
36
|
def lock_args
|
37
|
-
@lock_args ||= filtered_args
|
37
|
+
@lock_args ||= filtered_args || []
|
38
38
|
end
|
39
39
|
|
40
40
|
# Checks if the worker class has enabled lock_args
|
@@ -113,13 +113,13 @@ module SidekiqUniqueJobs
|
|
113
113
|
|
114
114
|
# the strategy to use as conflict resolution from sidekiq client
|
115
115
|
def on_client_conflict
|
116
|
-
@on_client_conflict ||= on_conflict["client"] if on_conflict.is_a?(Hash)
|
116
|
+
@on_client_conflict ||= on_conflict["client"] || on_conflict[:client] if on_conflict.is_a?(Hash)
|
117
117
|
@on_client_conflict ||= on_conflict
|
118
118
|
end
|
119
119
|
|
120
120
|
# the strategy to use as conflict resolution from sidekiq server
|
121
121
|
def on_server_conflict
|
122
|
-
@on_server_conflict ||= on_conflict["server"] if on_conflict.is_a?(Hash)
|
122
|
+
@on_server_conflict ||= on_conflict["server"] || on_conflict[:server] if on_conflict.is_a?(Hash)
|
123
123
|
@on_server_conflict ||= on_conflict
|
124
124
|
end
|
125
125
|
end
|
@@ -38,8 +38,8 @@ module SidekiqUniqueJobs
|
|
38
38
|
def initialize(item)
|
39
39
|
@item = item
|
40
40
|
@worker_class = item[CLASS]
|
41
|
-
@lock_args = item
|
42
|
-
@lock_prefix = item
|
41
|
+
@lock_args = item[LOCK_ARGS] || item[UNIQUE_ARGS] # TODO: Deprecate UNIQUE_ARGS
|
42
|
+
@lock_prefix = item[LOCK_PREFIX] || item[UNIQUE_PREFIX] # TODO: Deprecate UNIQUE_PREFIX
|
43
43
|
end
|
44
44
|
|
45
45
|
# Memoized lock_digest
|
@@ -31,7 +31,7 @@ local function log(message, prev_jid)
|
|
31
31
|
log_debug("ZADD", changelog, current_time, entry);
|
32
32
|
redis.call("ZADD", changelog, current_time, entry);
|
33
33
|
local total_entries = redis.call("ZCARD", changelog)
|
34
|
-
local removed_entries = redis.call("ZREMRANGEBYRANK", changelog,
|
34
|
+
local removed_entries = redis.call("ZREMRANGEBYRANK", changelog, 0, -1 * max_history)
|
35
35
|
if removed_entries > 0 then
|
36
36
|
log_debug("Removing", removed_entries , "entries from changelog (total entries", total_entries, "exceeds max_history:", max_history ..")");
|
37
37
|
end
|
@@ -21,7 +21,7 @@ module SidekiqUniqueJobs
|
|
21
21
|
# This will mess up sidekiq stats because a new job is created
|
22
22
|
def call
|
23
23
|
if sidekiq_worker_class?
|
24
|
-
if worker_class.perform_in(5, *item[ARGS])
|
24
|
+
if worker_class.set(queue: item["queue"].to_sym).perform_in(5, *item[ARGS])
|
25
25
|
reflect(:rescheduled, item)
|
26
26
|
else
|
27
27
|
reflect(:reschedule_failed, item)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "concurrent/version"
|
4
|
+
|
3
5
|
module SidekiqUniqueJobs
|
4
6
|
module Orphans
|
5
7
|
#
|
@@ -108,9 +110,13 @@ module SidekiqUniqueJobs
|
|
108
110
|
# @return [Hash]
|
109
111
|
#
|
110
112
|
def timer_task_options
|
111
|
-
{ run_now: true,
|
112
|
-
|
113
|
-
|
113
|
+
timer_task_options = { run_now: true, execution_interval: reaper_interval }
|
114
|
+
|
115
|
+
if VersionCheck.satisfied?(::Concurrent::VERSION, "< 1.1.10")
|
116
|
+
timer_task_options[:timeout_interval] = reaper_timeout
|
117
|
+
end
|
118
|
+
|
119
|
+
timer_task_options
|
114
120
|
end
|
115
121
|
|
116
122
|
#
|
@@ -15,6 +15,9 @@ module SidekiqUniqueJobs
|
|
15
15
|
# @return [String] the suffix for :RUN locks
|
16
16
|
RUN_SUFFIX = ":RUN"
|
17
17
|
#
|
18
|
+
# @return [Integer] the maximum combined length of sidekiq queues for running the reaper
|
19
|
+
MAX_QUEUE_LENGTH = 1000
|
20
|
+
#
|
18
21
|
# @!attribute [r] digests
|
19
22
|
# @return [SidekiqUniqueJobs::Digests] digest collection
|
20
23
|
attr_reader :digests
|
@@ -46,6 +49,8 @@ module SidekiqUniqueJobs
|
|
46
49
|
# @return [Integer] the number of reaped locks
|
47
50
|
#
|
48
51
|
def call
|
52
|
+
return if queues_very_full?
|
53
|
+
|
49
54
|
BatchDelete.call(orphans, conn)
|
50
55
|
end
|
51
56
|
|
@@ -212,6 +217,22 @@ module SidekiqUniqueJobs
|
|
212
217
|
end
|
213
218
|
end
|
214
219
|
|
220
|
+
# If sidekiq queues are very full, it becomes highly inefficient for the reaper
|
221
|
+
# because it must check every queued job to verify a digest is safe to delete
|
222
|
+
# The reaper checks queued jobs in batches of 50, adding 2 reads per digest
|
223
|
+
# With a queue length of 1,000 jobs, that's over 20 extra reads per digest.
|
224
|
+
def queues_very_full?
|
225
|
+
total_queue_size = 0
|
226
|
+
Sidekiq.redis do |conn|
|
227
|
+
queues(conn) do |queue|
|
228
|
+
total_queue_size += conn.llen("queue:#{queue}")
|
229
|
+
|
230
|
+
return true if total_queue_size > MAX_QUEUE_LENGTH
|
231
|
+
end
|
232
|
+
end
|
233
|
+
false
|
234
|
+
end
|
235
|
+
|
215
236
|
#
|
216
237
|
# Checks a sorted set for the existance of this digest
|
217
238
|
#
|
@@ -21,16 +21,24 @@ module Sidekiq
|
|
21
21
|
#
|
22
22
|
# @param [Hash<Symbol, Object>] tmp_config the temporary config to use
|
23
23
|
#
|
24
|
-
def self.use_options(tmp_config = {})
|
25
|
-
|
24
|
+
def self.use_options(tmp_config = {}) # rubocop:disable Metrics/MethodLength
|
25
|
+
if respond_to?(:default_job_options)
|
26
|
+
default_job_options.clear
|
27
|
+
self.default_job_options = tmp_config
|
28
|
+
else
|
29
|
+
default_worker_options.clear
|
30
|
+
self.default_worker_options = tmp_config
|
31
|
+
end
|
26
32
|
|
27
|
-
default_worker_options.clear
|
28
|
-
self.default_worker_options = tmp_config
|
29
33
|
yield
|
30
34
|
ensure
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
if respond_to?(:default_job_options)
|
36
|
+
default_job_options.clear
|
37
|
+
self.default_job_options = default_job_options
|
38
|
+
else
|
39
|
+
default_worker_options.clear
|
40
|
+
self.default_worker_options = DEFAULT_WORKER_OPTIONS
|
41
|
+
end
|
34
42
|
end
|
35
43
|
|
36
44
|
#
|
@@ -54,7 +62,13 @@ module Sidekiq
|
|
54
62
|
|
55
63
|
yield
|
56
64
|
ensure
|
57
|
-
self.sidekiq_options_hash =
|
65
|
+
self.sidekiq_options_hash =
|
66
|
+
if Sidekiq.respond_to?(:default_job_options)
|
67
|
+
Sidekiq.default_job_options
|
68
|
+
else
|
69
|
+
DEFAULT_WORKER_OPTIONS
|
70
|
+
end
|
71
|
+
|
58
72
|
sidekiq_options(old_options)
|
59
73
|
end
|
60
74
|
|
@@ -1,78 +1,84 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "concurrent/version"
|
4
|
+
require_relative "version_check"
|
5
|
+
|
3
6
|
module SidekiqUniqueJobs
|
4
7
|
# @see [Concurrent::TimerTask] https://www.rubydoc.info/gems/concurrent-ruby/Concurrent/TimerTask
|
5
8
|
#
|
6
9
|
class TimerTask < ::Concurrent::TimerTask
|
7
|
-
|
10
|
+
if VersionCheck.satisfied?(::Concurrent::VERSION, "< 1.1.10")
|
8
11
|
|
9
|
-
|
10
|
-
set_deref_options(opts)
|
12
|
+
private
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
@run_now = opts[:now] || opts[:run_now]
|
15
|
-
@executor = Concurrent::RubySingleThreadExecutor.new
|
16
|
-
@running = Concurrent::AtomicBoolean.new(false)
|
17
|
-
@task = task
|
18
|
-
@value = nil
|
14
|
+
def ns_initialize(opts, &task)
|
15
|
+
set_deref_options(opts)
|
19
16
|
|
20
|
-
|
21
|
-
|
17
|
+
self.execution_interval = opts[:execution] || opts[:execution_interval] || EXECUTION_INTERVAL
|
18
|
+
self.timeout_interval = opts[:timeout] || opts[:timeout_interval] || TIMEOUT_INTERVAL
|
19
|
+
@run_now = opts[:now] || opts[:run_now]
|
20
|
+
@executor = Concurrent::RubySingleThreadExecutor.new
|
21
|
+
@running = Concurrent::AtomicBoolean.new(false)
|
22
|
+
@task = task
|
23
|
+
@value = nil
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
Concurrent::ScheduledTask.execute(interval, args: [Concurrent::Event.new], &exec_task)
|
26
|
-
nil
|
27
|
-
end
|
25
|
+
self.observers = Concurrent::Collection::CopyOnNotifyObserverSet.new
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
timeout_task = -> { timeout_task(completion) }
|
34
|
-
|
35
|
-
Concurrent::ScheduledTask.execute(
|
36
|
-
timeout_interval,
|
37
|
-
args: [completion],
|
38
|
-
&timeout_task
|
39
|
-
)
|
40
|
-
@thread_completed = Concurrent::Event.new
|
41
|
-
|
42
|
-
@value = @reason = nil
|
43
|
-
@executor.post do
|
44
|
-
@value = @task.call(self)
|
45
|
-
rescue Exception => ex # rubocop:disable Lint/RescueException
|
46
|
-
@reason = ex
|
47
|
-
ensure
|
48
|
-
@thread_completed.set
|
28
|
+
def schedule_next_task(interval = execution_interval)
|
29
|
+
exec_task = ->(completion) { execute_task(completion) }
|
30
|
+
Concurrent::ScheduledTask.execute(interval, args: [Concurrent::Event.new], &exec_task)
|
31
|
+
nil
|
49
32
|
end
|
50
33
|
|
51
|
-
|
34
|
+
# @!visibility private
|
35
|
+
def execute_task(completion) # rubocop:disable Metrics/MethodLength
|
36
|
+
return nil unless @running.true?
|
52
37
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
[
|
38
|
+
timeout_task = -> { timeout_task(completion) }
|
39
|
+
|
40
|
+
Concurrent::ScheduledTask.execute(
|
41
|
+
timeout_interval,
|
42
|
+
args: [completion],
|
43
|
+
&timeout_task
|
44
|
+
)
|
45
|
+
@thread_completed = Concurrent::Event.new
|
46
|
+
|
47
|
+
@value = @reason = nil
|
48
|
+
@executor.post do
|
49
|
+
@value = @task.call(self)
|
50
|
+
rescue Exception => ex # rubocop:disable Lint/RescueException
|
51
|
+
@reason = ex
|
52
|
+
ensure
|
53
|
+
@thread_completed.set
|
58
54
|
end
|
55
|
+
|
56
|
+
@thread_completed.wait
|
57
|
+
|
58
|
+
if completion.try?
|
59
|
+
schedule_next_task
|
60
|
+
time = Time.now
|
61
|
+
observers.notify_observers do
|
62
|
+
[time, value, @reason]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
nil
|
59
66
|
end
|
60
|
-
nil
|
61
|
-
end
|
62
67
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
68
|
+
# @!visibility private
|
69
|
+
def timeout_task(completion)
|
70
|
+
return unless @running.true?
|
71
|
+
return unless completion.try?
|
67
72
|
|
68
|
-
|
69
|
-
|
70
|
-
|
73
|
+
@executor.kill
|
74
|
+
@executor.wait_for_termination
|
75
|
+
@executor = Concurrent::RubySingleThreadExecutor.new
|
71
76
|
|
72
|
-
|
77
|
+
@thread_completed.set
|
73
78
|
|
74
|
-
|
75
|
-
|
79
|
+
schedule_next_task
|
80
|
+
observers.notify_observers(Time.now, nil, Concurrent::TimeoutError.new)
|
81
|
+
end
|
76
82
|
end
|
77
83
|
end
|
78
84
|
end
|
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: 7.1.
|
4
|
+
version: 7.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikael Henriksson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brpoplpush-redis_script
|
@@ -257,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
257
|
- !ruby/object:Gem::Version
|
258
258
|
version: '0'
|
259
259
|
requirements: []
|
260
|
-
rubygems_version: 3.3.
|
260
|
+
rubygems_version: 3.3.7
|
261
261
|
signing_key:
|
262
262
|
specification_version: 4
|
263
263
|
summary: Sidekiq middleware that prevents duplicates jobs
|