sidekiq-unique-jobs 7.1.16 → 7.1.19
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 +42 -0
- 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/timer_task.rb +333 -60
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5432e71679519bcfbc3605de7c156e0820cf2c463ee9a5d458c1b59bd7c63fec
|
4
|
+
data.tar.gz: ecd548ff2add944949acc25341d92e2f74aee5256978d32ee74180ba1eacbd66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 926bde9f4894aba3806723c1d75faffdf8bde86514b37f69b4156ca12b3dd64228d6eb768a03f521d119ebb42f50bcfbe87392d788f54a6e49b233565743dcb4
|
7
|
+
data.tar.gz: 28d14de13123d83b6d948d8453a901efe0ae1667ebc0d6a444e702371579528eccb4ac42c298aa2eb425c23b402c155cc58f553def21cba9c7a6d46757a167e2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,47 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v7.1.18](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.18) (2022-04-05)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.17...v7.1.18)
|
6
|
+
|
7
|
+
**Implemented enhancements:**
|
8
|
+
|
9
|
+
- Make sure we reflect on execution failure [\#700](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/700) ([mhenrixon](https://github.com/mhenrixon))
|
10
|
+
|
11
|
+
## [v7.1.17](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.17) (2022-04-05)
|
12
|
+
|
13
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.16...v7.1.17)
|
14
|
+
|
15
|
+
## [v7.1.16](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.16) (2022-04-02)
|
16
|
+
|
17
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.15...v7.1.16)
|
18
|
+
|
19
|
+
**Implemented enhancements:**
|
20
|
+
|
21
|
+
- Abort Ruby Reaper when sidekiq queues are full [\#690](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/690) ([francesmcmullin](https://github.com/francesmcmullin))
|
22
|
+
- 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))
|
23
|
+
|
24
|
+
**Fixed bugs:**
|
25
|
+
|
26
|
+
- Hotfix: Ensure consistent lock args [\#699](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/699) ([mhenrixon](https://github.com/mhenrixon))
|
27
|
+
- Expire older changelog entries first [\#698](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/698) ([mhenrixon](https://github.com/mhenrixon))
|
28
|
+
- Fix drift [\#688](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/688) ([mhenrixon](https://github.com/mhenrixon))
|
29
|
+
|
30
|
+
**Closed issues:**
|
31
|
+
|
32
|
+
- concurrent-ruby has dropped support for TimerTask timeouts [\#697](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/697)
|
33
|
+
- Most recent changelogs are removed first [\#696](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/696)
|
34
|
+
- Improve README slightly [\#694](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/694)
|
35
|
+
- locksmith.rb:327: NoMethodError: undefined method `+' for nil:NilClass [\#686](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/686)
|
36
|
+
- lock\_timeout cannot be nil [\#675](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/675)
|
37
|
+
- Skip reaping when queues are too large [\#670](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/670)
|
38
|
+
|
39
|
+
**Merged pull requests:**
|
40
|
+
|
41
|
+
- Improve readme [\#695](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/695) ([fwolfst](https://github.com/fwolfst))
|
42
|
+
- Add funding\_uri to gemspec [\#693](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/693) ([fwolfst](https://github.com/fwolfst))
|
43
|
+
- Fix worker validator [\#685](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/685) ([victorfgs](https://github.com/victorfgs))
|
44
|
+
|
3
45
|
## [v7.1.15](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.15) (2022-02-10)
|
4
46
|
|
5
47
|
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.14...v7.1.15)
|
@@ -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
|
@@ -1,84 +1,357 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "concurrent/
|
4
|
-
|
3
|
+
require "concurrent/collection/copy_on_notify_observer_set"
|
4
|
+
require "concurrent/concern/dereferenceable"
|
5
|
+
require "concurrent/concern/observable"
|
6
|
+
require "concurrent/atomic/atomic_boolean"
|
7
|
+
require "concurrent/executor/executor_service"
|
8
|
+
require "concurrent/executor/ruby_executor_service"
|
9
|
+
require "concurrent/executor/safe_task_executor"
|
10
|
+
require "concurrent/scheduled_task"
|
5
11
|
|
6
12
|
module SidekiqUniqueJobs
|
7
|
-
#
|
13
|
+
# A very common concurrency pattern is to run a thread that performs a task at
|
14
|
+
# regular intervals. The thread that performs the task sleeps for the given
|
15
|
+
# interval then wakes up and performs the task. Lather, rinse, repeat... This
|
16
|
+
# pattern causes two problems. First, it is difficult to test the business
|
17
|
+
# logic of the task because the task itself is tightly coupled with the
|
18
|
+
# concurrency logic. Second, an exception raised while performing the task can
|
19
|
+
# cause the entire thread to abend. In a long-running application where the
|
20
|
+
# task thread is intended to run for days/weeks/years a crashed task thread
|
21
|
+
# can pose a significant problem. `TimerTask` alleviates both problems.
|
8
22
|
#
|
9
|
-
|
10
|
-
|
23
|
+
# When a `TimerTask` is launched it starts a thread for monitoring the
|
24
|
+
# execution interval. The `TimerTask` thread does not perform the task,
|
25
|
+
# however. Instead, the TimerTask launches the task on a separate thread.
|
26
|
+
# Should the task experience an unrecoverable crash only the task thread will
|
27
|
+
# crash. This makes the `TimerTask` very fault tolerant. Additionally, the
|
28
|
+
# `TimerTask` thread can respond to the success or failure of the task,
|
29
|
+
# performing logging or ancillary operations. `TimerTask` can also be
|
30
|
+
# configured with a timeout value allowing it to kill a task that runs too
|
31
|
+
# long.
|
32
|
+
#
|
33
|
+
# One other advantage of `TimerTask` is that it forces the business logic to
|
34
|
+
# be completely decoupled from the concurrency logic. The business logic can
|
35
|
+
# be tested separately then passed to the `TimerTask` for scheduling and
|
36
|
+
# running.
|
37
|
+
#
|
38
|
+
# In some cases it may be necessary for a `TimerTask` to affect its own
|
39
|
+
# execution cycle. To facilitate this, a reference to the TimerTask instance
|
40
|
+
# is passed as an argument to the provided block every time the task is
|
41
|
+
# executed.
|
42
|
+
#
|
43
|
+
# The `TimerTask` class includes the `Dereferenceable` mixin module so the
|
44
|
+
# result of the last execution is always available via the `#value` method.
|
45
|
+
# Dereferencing options can be passed to the `TimerTask` during construction or
|
46
|
+
# at any later time using the `#set_deref_options` method.
|
47
|
+
#
|
48
|
+
# `TimerTask` supports notification through the Ruby standard library
|
49
|
+
# {http://ruby-doc.org/stdlib-2.0/libdoc/observer/rdoc/Observable.html
|
50
|
+
# Observable} module. On execution the `TimerTask` will notify the observers
|
51
|
+
# with three arguments: time of execution, the result of the block (or nil on
|
52
|
+
# failure), and any raised exceptions (or nil on success). If the timeout
|
53
|
+
# interval is exceeded the observer will receive a `Concurrent::TimeoutError`
|
54
|
+
# object as the third argument.
|
55
|
+
#
|
56
|
+
# @!macro copy_options
|
57
|
+
#
|
58
|
+
# @example Basic usage
|
59
|
+
# task = Concurrent::TimerTask.new{ puts 'Boom!' }
|
60
|
+
# task.execute
|
61
|
+
#
|
62
|
+
# task.execution_interval #=> 60 (default)
|
63
|
+
# task.timeout_interval #=> 30 (default)
|
64
|
+
#
|
65
|
+
# # wait 60 seconds...
|
66
|
+
# #=> 'Boom!'
|
67
|
+
#
|
68
|
+
# task.shutdown #=> true
|
69
|
+
#
|
70
|
+
# @example Configuring `:execution_interval` and `:timeout_interval`
|
71
|
+
# task = Concurrent::TimerTask.new(execution_interval: 5, timeout_interval: 5) do
|
72
|
+
# puts 'Boom!'
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
# task.execution_interval #=> 5
|
76
|
+
# task.timeout_interval #=> 5
|
77
|
+
#
|
78
|
+
# @example Immediate execution with `:run_now`
|
79
|
+
# task = Concurrent::TimerTask.new(run_now: true){ puts 'Boom!' }
|
80
|
+
# task.execute
|
81
|
+
#
|
82
|
+
# #=> 'Boom!'
|
83
|
+
#
|
84
|
+
# @example Last `#value` and `Dereferenceable` mixin
|
85
|
+
# task = Concurrent::TimerTask.new(
|
86
|
+
# dup_on_deref: true,
|
87
|
+
# execution_interval: 5
|
88
|
+
# ){ Time.now }
|
89
|
+
#
|
90
|
+
# task.execute
|
91
|
+
# Time.now #=> 2013-11-07 18:06:50 -0500
|
92
|
+
# sleep(10)
|
93
|
+
# task.value #=> 2013-11-07 18:06:55 -0500
|
94
|
+
#
|
95
|
+
# @example Controlling execution from within the block
|
96
|
+
# timer_task = Concurrent::TimerTask.new(execution_interval: 1) do |task|
|
97
|
+
# task.execution_interval.times{ print 'Boom! ' }
|
98
|
+
# print "\n"
|
99
|
+
# task.execution_interval += 1
|
100
|
+
# if task.execution_interval > 5
|
101
|
+
# puts 'Stopping...'
|
102
|
+
# task.shutdown
|
103
|
+
# end
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
# timer_task.execute # blocking call - this task will stop itself
|
107
|
+
# #=> Boom!
|
108
|
+
# #=> Boom! Boom!
|
109
|
+
# #=> Boom! Boom! Boom!
|
110
|
+
# #=> Boom! Boom! Boom! Boom!
|
111
|
+
# #=> Boom! Boom! Boom! Boom! Boom!
|
112
|
+
# #=> Stopping...
|
113
|
+
#
|
114
|
+
# @example Observation
|
115
|
+
# class TaskObserver
|
116
|
+
# def update(time, result, ex)
|
117
|
+
# if result
|
118
|
+
# print "(#{time}) Execution successfully returned #{result}\n"
|
119
|
+
# elsif ex.is_a?(Concurrent::TimeoutError)
|
120
|
+
# print "(#{time}) Execution timed out\n"
|
121
|
+
# else
|
122
|
+
# print "(#{time}) Execution failed with error #{ex}\n"
|
123
|
+
# end
|
124
|
+
# end
|
125
|
+
# end
|
126
|
+
#
|
127
|
+
# task = Concurrent::TimerTask.new(execution_interval: 1, timeout_interval: 1){ 42 }
|
128
|
+
# task.add_observer(TaskObserver.new)
|
129
|
+
# task.execute
|
130
|
+
# sleep 4
|
131
|
+
#
|
132
|
+
# #=> (2013-10-13 19:08:58 -0400) Execution successfully returned 42
|
133
|
+
# #=> (2013-10-13 19:08:59 -0400) Execution successfully returned 42
|
134
|
+
# #=> (2013-10-13 19:09:00 -0400) Execution successfully returned 42
|
135
|
+
# task.shutdown
|
136
|
+
#
|
137
|
+
# task = Concurrent::TimerTask.new(execution_interval: 1, timeout_interval: 1){ sleep }
|
138
|
+
# task.add_observer(TaskObserver.new)
|
139
|
+
# task.execute
|
140
|
+
#
|
141
|
+
# #=> (2013-10-13 19:07:25 -0400) Execution timed out
|
142
|
+
# #=> (2013-10-13 19:07:27 -0400) Execution timed out
|
143
|
+
# #=> (2013-10-13 19:07:29 -0400) Execution timed out
|
144
|
+
# task.shutdown
|
145
|
+
#
|
146
|
+
# task = Concurrent::TimerTask.new(execution_interval: 1){ raise StandardError }
|
147
|
+
# task.add_observer(TaskObserver.new)
|
148
|
+
# task.execute
|
149
|
+
#
|
150
|
+
# #=> (2013-10-13 19:09:37 -0400) Execution failed with error StandardError
|
151
|
+
# #=> (2013-10-13 19:09:38 -0400) Execution failed with error StandardError
|
152
|
+
# #=> (2013-10-13 19:09:39 -0400) Execution failed with error StandardError
|
153
|
+
# task.shutdown
|
154
|
+
#
|
155
|
+
# @see http://ruby-doc.org/stdlib-2.0/libdoc/observer/rdoc/Observable.html
|
156
|
+
# @see http://docs.oracle.com/javase/7/docs/api/java/util/TimerTask.html
|
157
|
+
class TimerTask < Concurrent::RubyExecutorService # rubocop:disable Metrics/ClassLength
|
158
|
+
include Concurrent::Concern::Dereferenceable
|
159
|
+
include Concurrent::Concern::Observable
|
11
160
|
|
12
|
-
|
161
|
+
# Default `:execution_interval` in seconds.
|
162
|
+
EXECUTION_INTERVAL = 60
|
13
163
|
|
14
|
-
|
15
|
-
|
164
|
+
# Default `:timeout_interval` in seconds.
|
165
|
+
TIMEOUT_INTERVAL = 30
|
16
166
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
167
|
+
# Create a new TimerTask with the given task and configuration.
|
168
|
+
#
|
169
|
+
# @!macro timer_task_initialize
|
170
|
+
# @param [Hash] opts the options defining task execution.
|
171
|
+
# @option opts [Integer] :execution_interval number of seconds between
|
172
|
+
# task executions (default: EXECUTION_INTERVAL)
|
173
|
+
# @option opts [Integer] :timeout_interval number of seconds a task can
|
174
|
+
# run before it is considered to have failed (default: TIMEOUT_INTERVAL)
|
175
|
+
# @option opts [Boolean] :run_now Whether to run the task immediately
|
176
|
+
# upon instantiation or to wait until the first # execution_interval
|
177
|
+
# has passed (default: false)
|
178
|
+
#
|
179
|
+
# @!macro deref_options
|
180
|
+
#
|
181
|
+
# @raise ArgumentError when no block is given.
|
182
|
+
#
|
183
|
+
# @yield to the block after :execution_interval seconds have passed since
|
184
|
+
# the last yield
|
185
|
+
# @yieldparam task a reference to the `TimerTask` instance so that the
|
186
|
+
# block can control its own lifecycle. Necessary since `self` will
|
187
|
+
# refer to the execution context of the block rather than the running
|
188
|
+
# `TimerTask`.
|
189
|
+
#
|
190
|
+
# @return [TimerTask] the new `TimerTask`
|
191
|
+
def initialize(opts = {}, &task)
|
192
|
+
raise ArgumentError, "no block given" unless task
|
24
193
|
|
25
|
-
|
26
|
-
|
194
|
+
super
|
195
|
+
set_deref_options opts
|
196
|
+
end
|
27
197
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
198
|
+
# Is the executor running?
|
199
|
+
#
|
200
|
+
# @return [Boolean] `true` when running, `false` when shutting down or shutdown
|
201
|
+
def running?
|
202
|
+
@running.true?
|
203
|
+
end
|
33
204
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@
|
52
|
-
ensure
|
53
|
-
@thread_completed.set
|
205
|
+
# Execute a previously created `TimerTask`.
|
206
|
+
#
|
207
|
+
# @return [TimerTask] a reference to `self`
|
208
|
+
#
|
209
|
+
# @example Instance and execute in separate steps
|
210
|
+
# task = Concurrent::TimerTask.new(execution_interval: 10){ print "Hello World\n" }
|
211
|
+
# task.running? #=> false
|
212
|
+
# task.execute
|
213
|
+
# task.running? #=> true
|
214
|
+
#
|
215
|
+
# @example Instance and execute in one line
|
216
|
+
# task = Concurrent::TimerTask.new(execution_interval: 10){ print "Hello World\n" }.execute
|
217
|
+
# task.running? #=> true
|
218
|
+
def execute
|
219
|
+
synchronize do
|
220
|
+
if @running.false?
|
221
|
+
@running.make_true
|
222
|
+
schedule_next_task(@run_now ? 0 : @execution_interval)
|
54
223
|
end
|
224
|
+
end
|
225
|
+
self
|
226
|
+
end
|
227
|
+
|
228
|
+
# Create and execute a new `TimerTask`.
|
229
|
+
#
|
230
|
+
# @!macro timer_task_initialize
|
231
|
+
#
|
232
|
+
# @example
|
233
|
+
# task = Concurrent::TimerTask.execute(execution_interval: 10){ print "Hello World\n" }
|
234
|
+
# task.running? #=> true
|
235
|
+
def self.execute(opts = {}, &task)
|
236
|
+
SidekiqUniqueJobs::TimerTask.new(opts, &task).execute
|
237
|
+
end
|
55
238
|
|
56
|
-
|
239
|
+
# @!attribute [rw] execution_interval
|
240
|
+
# @return [Fixnum] Number of seconds after the task completes before the
|
241
|
+
# task is performed again.
|
242
|
+
def execution_interval
|
243
|
+
synchronize { @execution_interval }
|
244
|
+
end
|
57
245
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
246
|
+
# @!attribute [rw] execution_interval
|
247
|
+
# @return [Fixnum] Number of seconds after the task completes before the
|
248
|
+
# task is performed again.
|
249
|
+
def execution_interval=(value)
|
250
|
+
raise ArgumentError, "must be greater than zero" if (value = value.to_f) <= 0.0
|
251
|
+
|
252
|
+
synchronize { @execution_interval = value }
|
253
|
+
end
|
254
|
+
|
255
|
+
# @!attribute [rw] timeout_interval
|
256
|
+
# @return [Fixnum] Number of seconds the task can run before it is
|
257
|
+
# considered to have failed.
|
258
|
+
def timeout_interval
|
259
|
+
synchronize { @timeout_interval }
|
260
|
+
end
|
261
|
+
|
262
|
+
# @!attribute [rw] timeout_interval
|
263
|
+
# @return [Fixnum] Number of seconds the task can run before it is
|
264
|
+
# considered to have failed.
|
265
|
+
def timeout_interval=(value)
|
266
|
+
raise ArgumentError, "must be greater than zero" if (value = value.to_f) <= 0.0
|
267
|
+
|
268
|
+
synchronize { @timeout_interval = value }
|
269
|
+
end
|
270
|
+
|
271
|
+
private :post, :<<
|
272
|
+
|
273
|
+
private
|
274
|
+
|
275
|
+
def ns_initialize(opts, &task)
|
276
|
+
set_deref_options(opts)
|
277
|
+
|
278
|
+
self.execution_interval = opts[:execution] || opts[:execution_interval] || EXECUTION_INTERVAL
|
279
|
+
self.timeout_interval = opts[:timeout] || opts[:timeout_interval] || TIMEOUT_INTERVAL
|
280
|
+
@run_now = opts[:now] || opts[:run_now]
|
281
|
+
@executor = Concurrent::RubySingleThreadExecutor.new
|
282
|
+
@running = Concurrent::AtomicBoolean.new(false)
|
283
|
+
@task = task
|
284
|
+
@value = nil
|
285
|
+
|
286
|
+
self.observers = Concurrent::Collection::CopyOnNotifyObserverSet.new
|
287
|
+
end
|
288
|
+
|
289
|
+
# @!visibility private
|
290
|
+
def ns_shutdown_execution
|
291
|
+
@running.make_false
|
292
|
+
super
|
293
|
+
end
|
294
|
+
|
295
|
+
# @!visibility private
|
296
|
+
def ns_kill_execution
|
297
|
+
@running.make_false
|
298
|
+
super
|
299
|
+
end
|
300
|
+
|
301
|
+
# @!visibility private
|
302
|
+
def schedule_next_task(interval = execution_interval)
|
303
|
+
exec_task = ->(completion) { execute_task(completion) }
|
304
|
+
Concurrent::ScheduledTask.execute(interval, args: [Concurrent::Event.new], &exec_task)
|
305
|
+
nil
|
306
|
+
end
|
307
|
+
|
308
|
+
# @!visibility private
|
309
|
+
def execute_task(completion) # rubocop:disable Metrics/MethodLength
|
310
|
+
return nil unless @running.true?
|
67
311
|
|
68
|
-
|
69
|
-
def timeout_task(completion)
|
70
|
-
return unless @running.true?
|
71
|
-
return unless completion.try?
|
312
|
+
timeout_task = -> { timeout_task(completion) }
|
72
313
|
|
73
|
-
|
74
|
-
|
75
|
-
|
314
|
+
Concurrent::ScheduledTask.execute(
|
315
|
+
timeout_interval,
|
316
|
+
args: [completion],
|
317
|
+
&timeout_task
|
318
|
+
)
|
319
|
+
@thread_completed = Concurrent::Event.new
|
76
320
|
|
321
|
+
@value = @reason = nil
|
322
|
+
@executor.post do
|
323
|
+
@value = @task.call(self)
|
324
|
+
rescue Exception => ex # rubocop:disable Lint/RescueException
|
325
|
+
@reason = ex
|
326
|
+
ensure
|
77
327
|
@thread_completed.set
|
328
|
+
end
|
329
|
+
|
330
|
+
@thread_completed.wait
|
78
331
|
|
332
|
+
if completion.try?
|
79
333
|
schedule_next_task
|
80
|
-
|
334
|
+
time = Time.now
|
335
|
+
observers.notify_observers do
|
336
|
+
[time, value, @reason]
|
337
|
+
end
|
81
338
|
end
|
339
|
+
nil
|
340
|
+
end
|
341
|
+
|
342
|
+
# @!visibility private
|
343
|
+
def timeout_task(completion)
|
344
|
+
return unless @running.true?
|
345
|
+
return unless completion.try?
|
346
|
+
|
347
|
+
@executor.kill
|
348
|
+
@executor.wait_for_termination
|
349
|
+
@executor = Concurrent::RubySingleThreadExecutor.new
|
350
|
+
|
351
|
+
@thread_completed.set
|
352
|
+
|
353
|
+
schedule_next_task
|
354
|
+
observers.notify_observers(Time.now, nil, Concurrent::TimeoutError.new)
|
82
355
|
end
|
83
356
|
end
|
84
357
|
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.19
|
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-04-
|
11
|
+
date: 2022-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brpoplpush-redis_script
|