sidekiq-unique-jobs 7.1.5 → 7.1.25

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +244 -4
  3. data/README.md +16 -14
  4. data/lib/sidekiq_unique_jobs/batch_delete.rb +6 -6
  5. data/lib/sidekiq_unique_jobs/changelog.rb +3 -3
  6. data/lib/sidekiq_unique_jobs/config.rb +43 -4
  7. data/lib/sidekiq_unique_jobs/constants.rb +44 -44
  8. data/lib/sidekiq_unique_jobs/deprecation.rb +30 -0
  9. data/lib/sidekiq_unique_jobs/digests.rb +6 -9
  10. data/lib/sidekiq_unique_jobs/exceptions.rb +4 -3
  11. data/lib/sidekiq_unique_jobs/json.rb +7 -0
  12. data/lib/sidekiq_unique_jobs/lock/base_lock.rb +30 -22
  13. data/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +9 -3
  14. data/lib/sidekiq_unique_jobs/lock/until_executed.rb +14 -4
  15. data/lib/sidekiq_unique_jobs/lock/until_executing.rb +14 -4
  16. data/lib/sidekiq_unique_jobs/lock/until_expired.rb +13 -5
  17. data/lib/sidekiq_unique_jobs/lock/while_executing.rb +9 -4
  18. data/lib/sidekiq_unique_jobs/lock.rb +10 -10
  19. data/lib/sidekiq_unique_jobs/lock_args.rb +19 -15
  20. data/lib/sidekiq_unique_jobs/lock_config.rb +6 -6
  21. data/lib/sidekiq_unique_jobs/lock_digest.rb +6 -6
  22. data/lib/sidekiq_unique_jobs/lock_info.rb +2 -2
  23. data/lib/sidekiq_unique_jobs/lock_timeout.rb +4 -4
  24. data/lib/sidekiq_unique_jobs/lock_ttl.rb +5 -5
  25. data/lib/sidekiq_unique_jobs/locksmith.rb +5 -4
  26. data/lib/sidekiq_unique_jobs/logging.rb +9 -0
  27. data/lib/sidekiq_unique_jobs/lua/lock.lua +3 -3
  28. data/lib/sidekiq_unique_jobs/lua/shared/_common.lua +1 -1
  29. data/lib/sidekiq_unique_jobs/lua/unlock.lua +12 -5
  30. data/lib/sidekiq_unique_jobs/middleware/client.rb +3 -1
  31. data/lib/sidekiq_unique_jobs/middleware/server.rb +2 -0
  32. data/lib/sidekiq_unique_jobs/middleware.rb +4 -4
  33. data/lib/sidekiq_unique_jobs/on_conflict/reject.rb +4 -4
  34. data/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb +3 -3
  35. data/lib/sidekiq_unique_jobs/options_with_fallback.rb +5 -7
  36. data/lib/sidekiq_unique_jobs/orphans/manager.rb +38 -10
  37. data/lib/sidekiq_unique_jobs/orphans/ruby_reaper.rb +77 -14
  38. data/lib/sidekiq_unique_jobs/redis/string.rb +3 -1
  39. data/lib/sidekiq_unique_jobs/reflectable.rb +11 -2
  40. data/lib/sidekiq_unique_jobs/reflections.rb +12 -1
  41. data/lib/sidekiq_unique_jobs/server.rb +13 -1
  42. data/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +35 -13
  43. data/lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb +40 -21
  44. data/lib/sidekiq_unique_jobs/testing.rb +45 -20
  45. data/lib/sidekiq_unique_jobs/timer_task.rb +266 -45
  46. data/lib/sidekiq_unique_jobs/timing.rb +1 -1
  47. data/lib/sidekiq_unique_jobs/upgrade_locks.rb +6 -6
  48. data/lib/sidekiq_unique_jobs/version.rb +1 -1
  49. data/lib/sidekiq_unique_jobs/web/helpers.rb +1 -1
  50. data/lib/tasks/changelog.rake +16 -16
  51. metadata +11 -15
@@ -5,41 +5,56 @@ module SidekiqUniqueJobs
5
5
  #
6
6
  # @author Mikael Henriksson <mikael@mhenrixon.com>
7
7
  module SidekiqWorkerMethods
8
+ #
9
+ # @!attribute [r] job_class
10
+ # @return [Sidekiq::Worker] The Sidekiq::Worker implementation
11
+ attr_reader :job_class
12
+
8
13
  # Avoids duplicating worker_class.respond_to? in multiple places
9
14
  # @return [true, false]
10
- def worker_method_defined?(method_sym)
11
- worker_class.respond_to?(method_sym)
15
+ def job_method_defined?(method_sym)
16
+ job_class.respond_to?(method_sym)
12
17
  end
13
18
 
14
19
  # Wraps #get_sidekiq_options to always work with a hash
15
20
  # @return [Hash] of the worker class sidekiq options
16
- def worker_options
17
- return {} unless sidekiq_worker_class?
21
+ def job_options
22
+ return {} unless sidekiq_job_class?
18
23
 
19
- worker_class.get_sidekiq_options.deep_stringify_keys
24
+ job_class.get_sidekiq_options.deep_stringify_keys
20
25
  end
21
26
 
22
27
  # Tests that the
23
- # @return [true] if worker_class responds to get_sidekiq_options
24
- # @return [false] if worker_class does not respond to get_sidekiq_options
25
- def sidekiq_worker_class?
26
- worker_method_defined?(:get_sidekiq_options)
28
+ # @return [true] if job_class responds to get_sidekiq_options
29
+ # @return [false] if job_class does not respond to get_sidekiq_options
30
+ def sidekiq_job_class?
31
+ job_method_defined?(:get_sidekiq_options)
27
32
  end
28
33
 
29
- # The Sidekiq::Worker implementation
30
- # @return [Sidekiq::Worker]
31
- def worker_class
32
- @_worker_class ||= worker_class_constantize # rubocop:disable Naming/MemoizedInstanceVariableName
34
+ def job_class=(obj)
35
+ # this is what was originally passed in, it can be an instance or a class depending on sidekiq version
36
+ @original_job_class = obj
37
+ @job_class = job_class_constantize(obj)
33
38
  end
34
39
 
35
40
  # The hook to call after a successful unlock
36
41
  # @return [Proc]
37
- def after_unlock_hook
42
+ def after_unlock_hook # rubocop:disable Metrics/MethodLength
38
43
  lambda do
39
- if @worker_class.respond_to?(:after_unlock)
40
- @worker_class.after_unlock # instance method in sidekiq v6
41
- elsif worker_class.respond_to?(:after_unlock)
42
- worker_class.after_unlock # class method regardless of sidekiq version
44
+ if @original_job_class.respond_to?(:after_unlock)
45
+ # instance method in sidekiq v6
46
+ if @original_job_class.method(:after_unlock).arity.positive? # arity check to maintain backwards compatibility
47
+ @original_job_class.after_unlock(item)
48
+ else
49
+ @original_job_class.after_unlock
50
+ end
51
+ elsif job_class.respond_to?(:after_unlock)
52
+ # class method regardless of sidekiq version
53
+ if job_class.method(:after_unlock).arity.positive? # arity check to maintain backwards compatibility
54
+ job_class.after_unlock(item)
55
+ else
56
+ job_class.after_unlock
57
+ end
43
58
  end
44
59
  end
45
60
  end
@@ -48,7 +63,7 @@ module SidekiqUniqueJobs
48
63
  # failing back to the original argument when the constant can't be found
49
64
  #
50
65
  # @return [Sidekiq::Worker]
51
- def worker_class_constantize(klazz = @worker_class)
66
+ def job_class_constantize(klazz = @job_class)
52
67
  SidekiqUniqueJobs.safe_constantize(klazz)
53
68
  end
54
69
 
@@ -58,8 +73,12 @@ module SidekiqUniqueJobs
58
73
  #
59
74
  # @return [Hash<Symbol, Object>]
60
75
  #
61
- def default_worker_options
62
- Sidekiq.default_worker_options
76
+ def default_job_options
77
+ if Sidekiq.respond_to?(:default_job_options)
78
+ Sidekiq.default_job_options
79
+ else
80
+ Sidekiq.default_worker_options
81
+ end
63
82
  end
64
83
  end
65
84
  end
@@ -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
- old_options = default_worker_options.dup
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
- default_worker_options.clear
32
- self.default_worker_options = DEFAULT_WORKER_OPTIONS
33
- self.default_worker_options = old_options
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,20 +62,14 @@ module Sidekiq
54
62
 
55
63
  yield
56
64
  ensure
57
- self.sidekiq_options_hash = Sidekiq::DEFAULT_WORKER_OPTIONS
58
- sidekiq_options(old_options)
59
- end
60
-
61
- #
62
- # Clears the jobs for this worker and removes all locks
63
- #
64
- def clear
65
- jobs.each do |job|
66
- SidekiqUniqueJobs::Unlockable.unlock(job)
67
- end
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
68
71
 
69
- Sidekiq::Queues[queue].clear
70
- jobs.clear
72
+ sidekiq_options(old_options)
71
73
  end
72
74
  end
73
75
 
@@ -96,8 +98,31 @@ module Sidekiq
96
98
 
97
99
  SidekiqUniqueJobs::Digests.new.delete_by_pattern("*", count: 10_000)
98
100
  end
101
+
102
+ #
103
+ # Prepends deletion of locks to clear
104
+ #
105
+ module ClassMethods
106
+ #
107
+ # Clears the jobs for this worker and removes all locks
108
+ #
109
+ def clear
110
+ jobs.each do |job|
111
+ SidekiqUniqueJobs::Unlockable.unlock(job)
112
+ end
113
+
114
+ super
115
+ end
116
+ end
99
117
  end
100
118
 
101
119
  prepend Overrides
120
+
121
+ #
122
+ # Prepends methods to Sidekiq::Worker
123
+ #
124
+ module ClassMethods
125
+ prepend Overrides::ClassMethods
126
+ end
102
127
  end
103
128
  end
@@ -1,25 +1,279 @@
1
1
  # frozen_string_literal: true
2
2
 
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"
11
+
3
12
  module SidekiqUniqueJobs
4
- # @see [Concurrent::TimerTask] https://www.rubydoc.info/gems/concurrent-ruby/Concurrent/TimerTask
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.
22
+ #
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.
30
+ #
31
+ # One other advantage of `TimerTask` is that it forces the business logic to
32
+ # be completely decoupled from the concurrency logic. The business logic can
33
+ # be tested separately then passed to the `TimerTask` for scheduling and
34
+ # running.
35
+ #
36
+ # In some cases it may be necessary for a `TimerTask` to affect its own
37
+ # execution cycle. To facilitate this, a reference to the TimerTask instance
38
+ # is passed as an argument to the provided block every time the task is
39
+ # executed.
40
+ #
41
+ # The `TimerTask` class includes the `Dereferenceable` mixin module so the
42
+ # result of the last execution is always available via the `#value` method.
43
+ # Dereferencing options can be passed to the `TimerTask` during construction or
44
+ # at any later time using the `#set_deref_options` method.
45
+ #
46
+ # `TimerTask` supports notification through the Ruby standard library
47
+ # {http://ruby-doc.org/stdlib-2.0/libdoc/observer/rdoc/Observable.html
48
+ # Observable} module. On execution the `TimerTask` will notify the observers
49
+ # with three arguments: time of execution, the result of the block (or nil on
50
+ # failure), and any raised exceptions (or nil on success).
51
+ #
52
+ # @!macro copy_options
53
+ #
54
+ # @example Basic usage
55
+ # task = Concurrent::TimerTask.new{ puts 'Boom!' }
56
+ # task.execute
57
+ #
58
+ # task.execution_interval #=> 60 (default)
59
+ #
60
+ # # wait 60 seconds...
61
+ # #=> 'Boom!'
62
+ #
63
+ # task.shutdown #=> true
64
+ #
65
+ # @example Configuring `:execution_interval`
66
+ # task = Concurrent::TimerTask.new(execution_interval: 5) do
67
+ # puts 'Boom!'
68
+ # end
69
+ #
70
+ # task.execution_interval #=> 5
71
+ #
72
+ # @example Immediate execution with `:run_now`
73
+ # task = Concurrent::TimerTask.new(run_now: true){ puts 'Boom!' }
74
+ # task.execute
75
+ #
76
+ # #=> 'Boom!'
77
+ #
78
+ # @example Last `#value` and `Dereferenceable` mixin
79
+ # task = Concurrent::TimerTask.new(
80
+ # dup_on_deref: true,
81
+ # execution_interval: 5
82
+ # ){ Time.now }
5
83
  #
6
- class TimerTask < ::Concurrent::TimerTask
84
+ # task.execute
85
+ # Time.now #=> 2013-11-07 18:06:50 -0500
86
+ # sleep(10)
87
+ # task.value #=> 2013-11-07 18:06:55 -0500
88
+ #
89
+ # @example Controlling execution from within the block
90
+ # timer_task = Concurrent::TimerTask.new(execution_interval: 1) do |task|
91
+ # task.execution_interval.times{ print 'Boom! ' }
92
+ # print "\n"
93
+ # task.execution_interval += 1
94
+ # if task.execution_interval > 5
95
+ # puts 'Stopping...'
96
+ # task.shutdown
97
+ # end
98
+ # end
99
+ #
100
+ # timer_task.execute # blocking call - this task will stop itself
101
+ # #=> Boom!
102
+ # #=> Boom! Boom!
103
+ # #=> Boom! Boom! Boom!
104
+ # #=> Boom! Boom! Boom! Boom!
105
+ # #=> Boom! Boom! Boom! Boom! Boom!
106
+ # #=> Stopping...
107
+ #
108
+ # @example Observation
109
+ # class TaskObserver
110
+ # def update(time, result, ex)
111
+ # if result
112
+ # print "(#{time}) Execution successfully returned #{result}\n"
113
+ # else
114
+ # print "(#{time}) Execution failed with error #{ex}\n"
115
+ # end
116
+ # end
117
+ # end
118
+ #
119
+ # task = Concurrent::TimerTask.new(execution_interval: 1){ 42 }
120
+ # task.add_observer(TaskObserver.new)
121
+ # task.execute
122
+ # sleep 4
123
+ #
124
+ # #=> (2013-10-13 19:08:58 -0400) Execution successfully returned 42
125
+ # #=> (2013-10-13 19:08:59 -0400) Execution successfully returned 42
126
+ # #=> (2013-10-13 19:09:00 -0400) Execution successfully returned 42
127
+ # task.shutdown
128
+ #
129
+ # task = Concurrent::TimerTask.new(execution_interval: 1){ sleep }
130
+ # task.add_observer(TaskObserver.new)
131
+ # task.execute
132
+ #
133
+ # #=> (2013-10-13 19:07:25 -0400) Execution timed out
134
+ # #=> (2013-10-13 19:07:27 -0400) Execution timed out
135
+ # #=> (2013-10-13 19:07:29 -0400) Execution timed out
136
+ # task.shutdown
137
+ #
138
+ # task = Concurrent::TimerTask.new(execution_interval: 1){ raise StandardError }
139
+ # task.add_observer(TaskObserver.new)
140
+ # task.execute
141
+ #
142
+ # #=> (2013-10-13 19:09:37 -0400) Execution failed with error StandardError
143
+ # #=> (2013-10-13 19:09:38 -0400) Execution failed with error StandardError
144
+ # #=> (2013-10-13 19:09:39 -0400) Execution failed with error StandardError
145
+ # task.shutdown
146
+ #
147
+ # @see http://ruby-doc.org/stdlib-2.0/libdoc/observer/rdoc/Observable.html
148
+ # @see http://docs.oracle.com/javase/7/docs/api/java/util/TimerTask.html
149
+ class TimerTask < Concurrent::RubyExecutorService
150
+ include Concurrent::Concern::Dereferenceable
151
+ include Concurrent::Concern::Observable
152
+
153
+ # Default `:execution_interval` in seconds.
154
+ EXECUTION_INTERVAL = 60
155
+
156
+ # Default `:timeout_interval` in seconds.
157
+ TIMEOUT_INTERVAL = 30
158
+
159
+ # Create a new TimerTask with the given task and configuration.
160
+ #
161
+ # @!macro timer_task_initialize
162
+ # @param [Hash] opts the options defining task execution.
163
+ # @option opts [Integer] :execution_interval number of seconds between
164
+ # task executions (default: EXECUTION_INTERVAL)
165
+ # @option opts [Boolean] :run_now Whether to run the task immediately
166
+ # upon instantiation or to wait until the first # execution_interval
167
+ # has passed (default: false)
168
+ #
169
+ # @!macro deref_options
170
+ #
171
+ # @raise ArgumentError when no block is given.
172
+ #
173
+ # @yield to the block after :execution_interval seconds have passed since
174
+ # the last yield
175
+ # @yieldparam task a reference to the `TimerTask` instance so that the
176
+ # block can control its own lifecycle. Necessary since `self` will
177
+ # refer to the execution context of the block rather than the running
178
+ # `TimerTask`.
179
+ #
180
+ # @return [TimerTask] the new `TimerTask`
181
+ def initialize(opts = {}, &task)
182
+ raise ArgumentError, "no block given" unless task
183
+
184
+ super
185
+ set_deref_options opts
186
+ end
187
+
188
+ # Is the executor running?
189
+ #
190
+ # @return [Boolean] `true` when running, `false` when shutting down or shutdown
191
+ def running?
192
+ @running.true?
193
+ end
194
+
195
+ # Execute a previously created `TimerTask`.
196
+ #
197
+ # @return [TimerTask] a reference to `self`
198
+ #
199
+ # @example Instance and execute in separate steps
200
+ # task = Concurrent::TimerTask.new(execution_interval: 10){ print "Hello World\n" }
201
+ # task.running? #=> false
202
+ # task.execute
203
+ # task.running? #=> true
204
+ #
205
+ # @example Instance and execute in one line
206
+ # task = Concurrent::TimerTask.new(execution_interval: 10){ print "Hello World\n" }.execute
207
+ # task.running? #=> true
208
+ def execute
209
+ synchronize do
210
+ if @running.false?
211
+ @running.make_true
212
+ schedule_next_task(@run_now ? 0 : @execution_interval)
213
+ end
214
+ end
215
+ self
216
+ end
217
+
218
+ # Create and execute a new `TimerTask`.
219
+ #
220
+ # @!macro timer_task_initialize
221
+ #
222
+ # @example
223
+ # task = Concurrent::TimerTask.execute(execution_interval: 10){ print "Hello World\n" }
224
+ # task.running? #=> true
225
+ def self.execute(opts = {}, &task)
226
+ TimerTask.new(opts, &task).execute
227
+ end
228
+
229
+ # @!attribute [rw] execution_interval
230
+ # @return [Fixnum] Number of seconds after the task completes before the
231
+ # task is performed again.
232
+ def execution_interval
233
+ synchronize { @execution_interval }
234
+ end
235
+
236
+ # @!attribute [rw] execution_interval
237
+ # @return [Fixnum] Number of seconds after the task completes before the
238
+ # task is performed again.
239
+ def execution_interval=(value)
240
+ raise ArgumentError, "must be greater than zero" if (value = value.to_f) <= 0.0
241
+
242
+ synchronize { @execution_interval = value }
243
+ end
244
+
245
+ private :post, :<<
246
+
7
247
  private
8
248
 
9
249
  def ns_initialize(opts, &task)
10
250
  set_deref_options(opts)
11
251
 
12
252
  self.execution_interval = opts[:execution] || opts[:execution_interval] || EXECUTION_INTERVAL
13
- self.timeout_interval = opts[:timeout] || opts[:timeout_interval] || TIMEOUT_INTERVAL
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
253
+ if opts[:timeout] || opts[:timeout_interval]
254
+ warn "TimeTask timeouts are now ignored as these were not able to be implemented correctly"
255
+ end
256
+ @run_now = opts[:now] || opts[:run_now]
257
+ @executor = Concurrent::SafeTaskExecutor.new(task)
258
+ @running = Concurrent::AtomicBoolean.new(false)
259
+ @value = nil
19
260
 
20
261
  self.observers = Concurrent::Collection::CopyOnNotifyObserverSet.new
21
262
  end
22
263
 
264
+ # @!visibility private
265
+ def ns_shutdown_execution
266
+ @running.make_false
267
+ super
268
+ end
269
+
270
+ # @!visibility private
271
+ def ns_kill_execution
272
+ @running.make_false
273
+ super
274
+ end
275
+
276
+ # @!visibility private
23
277
  def schedule_next_task(interval = execution_interval)
24
278
  exec_task = ->(completion) { execute_task(completion) }
25
279
  Concurrent::ScheduledTask.execute(interval, args: [Concurrent::Event.new], &exec_task)
@@ -27,52 +281,19 @@ module SidekiqUniqueJobs
27
281
  end
28
282
 
29
283
  # @!visibility private
30
- def execute_task(completion) # rubocop:disable Metrics/MethodLength
284
+ def execute_task(completion)
31
285
  return nil unless @running.true?
32
286
 
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
49
- end
50
-
51
- @thread_completed.wait
52
-
287
+ _success, value, reason = @executor.execute(self)
53
288
  if completion.try?
289
+ self.value = value
54
290
  schedule_next_task
55
291
  time = Time.now
56
292
  observers.notify_observers do
57
- [time, value, @reason]
293
+ [time, self.value, reason]
58
294
  end
59
295
  end
60
296
  nil
61
297
  end
62
-
63
- # @!visibility private
64
- def timeout_task(completion)
65
- return unless @running.true?
66
- return unless completion.try?
67
-
68
- @executor.kill
69
- @executor.wait_for_termination
70
- @executor = Concurrent::RubySingleThreadExecutor.new
71
-
72
- @thread_completed.set
73
-
74
- schedule_next_task
75
- observers.notify_observers(Time.now, nil, Concurrent::TimeoutError.new)
76
- end
77
298
  end
78
299
  end
@@ -48,7 +48,7 @@ module SidekiqUniqueJobs
48
48
  # @return [Float]
49
49
  #
50
50
  def clock_stamp
51
- if Process.const_defined?("CLOCK_MONOTONIC")
51
+ if Process.const_defined?(:CLOCK_MONOTONIC)
52
52
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
53
53
  else
54
54
  now_f
@@ -87,9 +87,9 @@ module SidekiqUniqueJobs
87
87
  digest = grabbed_key.gsub(":GRABBED", "")
88
88
  locks = conn.hgetall(grabbed_key)
89
89
 
90
- conn.pipelined do
91
- conn.hmset(locked_key, *locks.to_a)
92
- conn.zadd(DIGESTS, locks.values.first, digest)
90
+ conn.pipelined do |pipeline|
91
+ pipeline.hmset(locked_key, *locks.to_a)
92
+ pipeline.zadd(DIGESTS, locks.values.first, digest)
93
93
  end
94
94
  end
95
95
 
@@ -114,11 +114,11 @@ module SidekiqUniqueJobs
114
114
  def batch_delete(*keys)
115
115
  return if keys.empty?
116
116
 
117
- conn.pipelined do
117
+ conn.pipelined do |pipeline|
118
118
  if VersionCheck.satisfied?(redis_version, ">= 4.0.0")
119
- conn.unlink(*keys)
119
+ pipeline.unlink(*keys)
120
120
  else
121
- conn.del(*keys)
121
+ pipeline.del(*keys)
122
122
  end
123
123
  end
124
124
  end
@@ -3,5 +3,5 @@
3
3
  module SidekiqUniqueJobs
4
4
  #
5
5
  # @return [String] the current SidekiqUniqueJobs version
6
- VERSION = "7.1.5"
6
+ VERSION = "7.1.25"
7
7
  end
@@ -27,7 +27,7 @@ module SidekiqUniqueJobs
27
27
  # @return [String] the file contents of the template
28
28
  #
29
29
  def unique_template(name)
30
- File.open(unique_filename(name)).read
30
+ File.read(unique_filename(name))
31
31
  end
32
32
 
33
33
  #
@@ -1,23 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Style/MutableConstant
4
+ CHANGELOG_CMD = %w[
5
+ github_changelog_generator
6
+ --no-verbose
7
+ --user
8
+ mhenrixon
9
+ --project
10
+ sidekiq-unique-jobs
11
+ --token
12
+ ]
13
+ ADD_CHANGELOG_CMD = "git add --all"
14
+ COMMIT_CHANGELOG_CMD = "git commit -a -m 'Update changelog'"
15
+ # rubocop:enable Style/MutableConstant
16
+
3
17
  desc "Generate a Changelog"
4
18
  task :changelog do
5
- # rubocop:disable Style/MutableConstant
6
- CHANGELOG_CMD ||= %w[
7
- github_changelog_generator
8
- --no-verbose
9
- --user
10
- mhenrixon
11
- --project
12
- sidekiq-unique-jobs
13
- --token
14
- ]
15
- ADD_CHANGELOG_CMD ||= "git add --all"
16
- COMMIT_CHANGELOG_CMD ||= "git commit -a -m 'Update changelog'"
17
- # rubocop:enable Style/MutableConstant
18
-
19
- sh("git checkout master")
20
- sh(*CHANGELOG_CMD.push(ENV["CHANGELOG_GITHUB_TOKEN"]))
19
+ sh("git checkout main")
20
+ sh(*CHANGELOG_CMD.push(ENV.fetch("CHANGELOG_GITHUB_TOKEN", nil)))
21
21
  sh(ADD_CHANGELOG_CMD)
22
22
  sh(COMMIT_CHANGELOG_CMD)
23
23
  end