sidekiq-unique-jobs 7.1.8 → 8.0.3
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 +331 -2
- data/README.md +28 -25
- data/lib/sidekiq_unique_jobs/batch_delete.rb +7 -10
- data/lib/sidekiq_unique_jobs/changelog.rb +7 -17
- data/lib/sidekiq_unique_jobs/cli.rb +33 -8
- data/lib/sidekiq_unique_jobs/config.rb +5 -0
- data/lib/sidekiq_unique_jobs/connection.rb +4 -7
- data/lib/sidekiq_unique_jobs/constants.rb +1 -0
- data/lib/sidekiq_unique_jobs/core_ext.rb +1 -1
- data/lib/sidekiq_unique_jobs/digests.rb +7 -17
- data/lib/sidekiq_unique_jobs/exceptions.rb +3 -3
- data/lib/sidekiq_unique_jobs/expiring_digests.rb +14 -0
- data/lib/sidekiq_unique_jobs/job.rb +6 -1
- data/lib/sidekiq_unique_jobs/key.rb +13 -8
- data/lib/sidekiq_unique_jobs/lock/until_executed.rb +6 -1
- data/lib/sidekiq_unique_jobs/lock/until_executing.rb +4 -0
- data/lib/sidekiq_unique_jobs/lock/until_expired.rb +3 -1
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +5 -3
- data/lib/sidekiq_unique_jobs/lock.rb +32 -12
- data/lib/sidekiq_unique_jobs/lock_args.rb +19 -15
- data/lib/sidekiq_unique_jobs/lock_config.rb +6 -6
- data/lib/sidekiq_unique_jobs/lock_digest.rb +7 -7
- data/lib/sidekiq_unique_jobs/lock_info.rb +2 -2
- data/lib/sidekiq_unique_jobs/lock_timeout.rb +4 -4
- data/lib/sidekiq_unique_jobs/lock_ttl.rb +4 -4
- data/lib/sidekiq_unique_jobs/lock_type.rb +37 -0
- data/lib/sidekiq_unique_jobs/locksmith.rb +36 -13
- data/lib/sidekiq_unique_jobs/logging.rb +14 -0
- data/lib/sidekiq_unique_jobs/lua/delete.lua +3 -6
- data/lib/sidekiq_unique_jobs/lua/delete_by_digest.lua +3 -6
- data/lib/sidekiq_unique_jobs/lua/delete_job_by_digest.lua +1 -1
- data/lib/sidekiq_unique_jobs/lua/find_digest_in_queues.lua +1 -1
- data/lib/sidekiq_unique_jobs/lua/lock.lua +16 -10
- data/lib/sidekiq_unique_jobs/lua/lock_until_expired.lua +92 -0
- data/lib/sidekiq_unique_jobs/lua/locked.lua +1 -1
- data/lib/sidekiq_unique_jobs/lua/queue.lua +1 -1
- data/lib/sidekiq_unique_jobs/lua/reap_orphans.lua +33 -8
- data/lib/sidekiq_unique_jobs/lua/shared/_common.lua +1 -6
- data/lib/sidekiq_unique_jobs/lua/shared/_delete_from_sorted_set.lua +1 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_process_set.lua +1 -1
- data/lib/sidekiq_unique_jobs/lua/unlock.lua +16 -15
- data/lib/sidekiq_unique_jobs/lua/update_version.lua +1 -1
- data/lib/sidekiq_unique_jobs/lua/upgrade.lua +1 -3
- data/lib/sidekiq_unique_jobs/middleware/client.rb +2 -0
- data/lib/sidekiq_unique_jobs/middleware/server.rb +2 -0
- data/lib/sidekiq_unique_jobs/middleware.rb +4 -4
- data/lib/sidekiq_unique_jobs/on_conflict/reject.rb +0 -43
- data/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb +3 -3
- data/lib/sidekiq_unique_jobs/options_with_fallback.rb +4 -4
- data/lib/sidekiq_unique_jobs/orphans/lua_reaper.rb +1 -1
- data/lib/sidekiq_unique_jobs/orphans/manager.rb +6 -13
- data/lib/sidekiq_unique_jobs/orphans/ruby_reaper.rb +95 -16
- data/lib/sidekiq_unique_jobs/redis/sorted_set.rb +9 -2
- data/lib/sidekiq_unique_jobs/redis/string.rb +3 -1
- data/lib/sidekiq_unique_jobs/reflections.rb +1 -1
- data/lib/sidekiq_unique_jobs/script/caller.rb +14 -8
- data/lib/sidekiq_unique_jobs/server.rb +0 -1
- data/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +1 -1
- data/lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb +14 -4
- data/lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb +40 -21
- data/lib/sidekiq_unique_jobs/testing.rb +53 -21
- data/lib/sidekiq_unique_jobs/timer_task.rb +266 -45
- data/lib/sidekiq_unique_jobs/timing.rb +1 -1
- data/lib/sidekiq_unique_jobs/upgrade_locks.rb +11 -14
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- data/lib/sidekiq_unique_jobs/web/helpers.rb +15 -3
- data/lib/sidekiq_unique_jobs/web/views/changelogs.erb +44 -38
- data/lib/sidekiq_unique_jobs/web/views/lock.erb +5 -3
- data/lib/sidekiq_unique_jobs/web/views/locks.erb +42 -37
- data/lib/sidekiq_unique_jobs/web.rb +26 -8
- data/lib/sidekiq_unique_jobs.rb +2 -0
- data/lib/tasks/changelog.rake +1 -1
- metadata +16 -43
@@ -29,10 +29,10 @@ module SidekiqUniqueJobs
|
|
29
29
|
# @yieldparam [<type>] if <description>
|
30
30
|
# @yieldreturn [<type>] <describe what yield should return>
|
31
31
|
def call(worker_class, item, queue, redis_pool = nil)
|
32
|
-
@
|
33
|
-
@
|
34
|
-
@
|
35
|
-
|
32
|
+
@item = item
|
33
|
+
@queue = queue
|
34
|
+
@redis_pool = redis_pool
|
35
|
+
self.job_class = worker_class
|
36
36
|
return yield if unique_disabled?
|
37
37
|
|
38
38
|
SidekiqUniqueJobs::Job.prepare(item) unless item[LOCK_DIGEST]
|
@@ -12,33 +12,6 @@ module SidekiqUniqueJobs
|
|
12
12
|
def call
|
13
13
|
log_info { "Adding dead #{item[CLASS]} job #{item[JID]}" }
|
14
14
|
|
15
|
-
if deadset_kill?
|
16
|
-
deadset_kill
|
17
|
-
else
|
18
|
-
push_to_deadset
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
# Sidekiq version compatibility check
|
24
|
-
# @api private
|
25
|
-
#
|
26
|
-
#
|
27
|
-
# @return [true, false] depending on if Sidekiq::Deadset responds to kill
|
28
|
-
#
|
29
|
-
def deadset_kill?
|
30
|
-
deadset.respond_to?(:kill)
|
31
|
-
end
|
32
|
-
|
33
|
-
#
|
34
|
-
# Use Sidekiqs built in Sidekiq::DeadSet#kill
|
35
|
-
# to get rid of the job
|
36
|
-
# @api private
|
37
|
-
#
|
38
|
-
#
|
39
|
-
# @return [void]
|
40
|
-
#
|
41
|
-
def deadset_kill
|
42
15
|
if kill_with_options?
|
43
16
|
kill_job_with_options
|
44
17
|
else
|
@@ -88,22 +61,6 @@ module SidekiqUniqueJobs
|
|
88
61
|
@deadset ||= Sidekiq::DeadSet.new
|
89
62
|
end
|
90
63
|
|
91
|
-
#
|
92
|
-
# Used for compatibility with older Sidekiq versions
|
93
|
-
#
|
94
|
-
#
|
95
|
-
# @return [void]
|
96
|
-
#
|
97
|
-
def push_to_deadset
|
98
|
-
redis do |conn|
|
99
|
-
conn.multi do
|
100
|
-
conn.zadd("dead", now_f, payload)
|
101
|
-
conn.zremrangebyscore("dead", "-inf", now_f - Sidekiq::DeadSet.timeout)
|
102
|
-
conn.zremrangebyrank("dead", 0, -Sidekiq::DeadSet.max_jobs)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
64
|
#
|
108
65
|
# The Sidekiq job hash as JSON
|
109
66
|
#
|
@@ -14,14 +14,14 @@ module SidekiqUniqueJobs
|
|
14
14
|
# @param [Hash] item sidekiq job hash
|
15
15
|
def initialize(item, redis_pool = nil)
|
16
16
|
super(item, redis_pool)
|
17
|
-
|
17
|
+
self.job_class = item[CLASS]
|
18
18
|
end
|
19
19
|
|
20
20
|
# Create a new job from the current one.
|
21
21
|
# This will mess up sidekiq stats because a new job is created
|
22
22
|
def call
|
23
|
-
if
|
24
|
-
if
|
23
|
+
if sidekiq_job_class?
|
24
|
+
if job_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)
|
@@ -6,7 +6,7 @@ module SidekiqUniqueJobs
|
|
6
6
|
# Requires the following methods to be defined in the including class
|
7
7
|
# 1. item (required)
|
8
8
|
# 2. options (can be nil)
|
9
|
-
# 3.
|
9
|
+
# 3. job_class (required, can be anything)
|
10
10
|
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
11
11
|
module OptionsWithFallback
|
12
12
|
def self.included(base)
|
@@ -55,7 +55,7 @@ module SidekiqUniqueJobs
|
|
55
55
|
# The type of lock for this worker
|
56
56
|
#
|
57
57
|
#
|
58
|
-
# @return [Symbol]
|
58
|
+
# @return [Symbol, NilClass]
|
59
59
|
#
|
60
60
|
def lock_type
|
61
61
|
@lock_type ||= options[LOCK] || item[LOCK]
|
@@ -69,8 +69,8 @@ module SidekiqUniqueJobs
|
|
69
69
|
#
|
70
70
|
def options
|
71
71
|
@options ||= begin
|
72
|
-
opts =
|
73
|
-
opts.merge!(
|
72
|
+
opts = default_job_options.dup
|
73
|
+
opts.merge!(job_options) if sidekiq_job_class?
|
74
74
|
(opts || {}).stringify_keys
|
75
75
|
end
|
76
76
|
end
|
@@ -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
|
#
|
@@ -70,7 +72,7 @@ module SidekiqUniqueJobs
|
|
70
72
|
# @return [<type>] <description>
|
71
73
|
#
|
72
74
|
def task
|
73
|
-
@task ||= default_task
|
75
|
+
@task ||= default_task # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
|
74
76
|
end
|
75
77
|
|
76
78
|
#
|
@@ -98,7 +100,7 @@ module SidekiqUniqueJobs
|
|
98
100
|
# @return [void]
|
99
101
|
#
|
100
102
|
def task=(task)
|
101
|
-
@task = task
|
103
|
+
@task = task # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
|
102
104
|
end
|
103
105
|
|
104
106
|
#
|
@@ -108,9 +110,7 @@ module SidekiqUniqueJobs
|
|
108
110
|
# @return [Hash]
|
109
111
|
#
|
110
112
|
def timer_task_options
|
111
|
-
{ run_now: true,
|
112
|
-
execution_interval: reaper_interval,
|
113
|
-
timeout_interval: reaper_timeout }
|
113
|
+
{ run_now: true, execution_interval: reaper_interval }
|
114
114
|
end
|
115
115
|
|
116
116
|
#
|
@@ -127,13 +127,6 @@ module SidekiqUniqueJobs
|
|
127
127
|
SidekiqUniqueJobs.config.reaper_interval
|
128
128
|
end
|
129
129
|
|
130
|
-
#
|
131
|
-
# @see SidekiqUniqueJobs::Config#reaper_timeout
|
132
|
-
#
|
133
|
-
def reaper_timeout
|
134
|
-
SidekiqUniqueJobs.config.reaper_timeout
|
135
|
-
end
|
136
|
-
|
137
130
|
#
|
138
131
|
# A context to use for all log entries
|
139
132
|
#
|
@@ -224,7 +217,7 @@ module SidekiqUniqueJobs
|
|
224
217
|
|
225
218
|
#
|
226
219
|
# Reaper interval with a little drift
|
227
|
-
# Redis isn't exact enough so to give a little
|
220
|
+
# Redis isn't exact enough so to give a little buffer,
|
228
221
|
# we add a tiny value to the reaper interval.
|
229
222
|
#
|
230
223
|
#
|
@@ -9,11 +9,17 @@ module SidekiqUniqueJobs
|
|
9
9
|
#
|
10
10
|
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
11
11
|
#
|
12
|
+
# rubocop:disable Metrics/ClassLength
|
12
13
|
class RubyReaper < Reaper
|
14
|
+
include SidekiqUniqueJobs::Timing
|
15
|
+
|
13
16
|
#
|
14
17
|
# @return [String] the suffix for :RUN locks
|
15
18
|
RUN_SUFFIX = ":RUN"
|
16
19
|
#
|
20
|
+
# @return [Integer] the maximum combined length of sidekiq queues for running the reaper
|
21
|
+
MAX_QUEUE_LENGTH = 1000
|
22
|
+
#
|
17
23
|
# @!attribute [r] digests
|
18
24
|
# @return [SidekiqUniqueJobs::Digests] digest collection
|
19
25
|
attr_reader :digests
|
@@ -26,6 +32,22 @@ module SidekiqUniqueJobs
|
|
26
32
|
# @return [Redis::SortedSet] the Sidekiq RetrySet
|
27
33
|
attr_reader :retried
|
28
34
|
|
35
|
+
#
|
36
|
+
# @!attribute [r] start_time
|
37
|
+
# @return [Integer] The timestamp this execution started represented as Time (used for locks)
|
38
|
+
attr_reader :start_time
|
39
|
+
|
40
|
+
#
|
41
|
+
# @!attribute [r] start_time
|
42
|
+
# @return [Integer] The clock stamp this execution started represented as integer
|
43
|
+
# (used for redis compatibility as it is more accurate than time)
|
44
|
+
attr_reader :start_source
|
45
|
+
|
46
|
+
#
|
47
|
+
# @!attribute [r] timeout_ms
|
48
|
+
# @return [Integer] The allowed ms before timeout
|
49
|
+
attr_reader :timeout_ms
|
50
|
+
|
29
51
|
#
|
30
52
|
# Initialize a new instance of DeleteOrphans
|
31
53
|
#
|
@@ -33,9 +55,12 @@ module SidekiqUniqueJobs
|
|
33
55
|
#
|
34
56
|
def initialize(conn)
|
35
57
|
super(conn)
|
36
|
-
@digests
|
37
|
-
@scheduled
|
38
|
-
@retried
|
58
|
+
@digests = SidekiqUniqueJobs::Digests.new
|
59
|
+
@scheduled = Redis::SortedSet.new(SCHEDULE)
|
60
|
+
@retried = Redis::SortedSet.new(RETRY)
|
61
|
+
@start_time = Time.now
|
62
|
+
@start_source = time_source.call
|
63
|
+
@timeout_ms = SidekiqUniqueJobs.config.reaper_timeout * 1000
|
39
64
|
end
|
40
65
|
|
41
66
|
#
|
@@ -45,22 +70,55 @@ module SidekiqUniqueJobs
|
|
45
70
|
# @return [Integer] the number of reaped locks
|
46
71
|
#
|
47
72
|
def call
|
73
|
+
return if queues_very_full?
|
74
|
+
|
75
|
+
BatchDelete.call(expired_digests, conn)
|
48
76
|
BatchDelete.call(orphans, conn)
|
49
77
|
end
|
50
78
|
|
79
|
+
def expired_digests
|
80
|
+
max_score = (start_time - reaper_timeout).to_f
|
81
|
+
|
82
|
+
conn.zrange(EXPIRING_DIGESTS, 0, max_score, byscore: true)
|
83
|
+
end
|
84
|
+
|
51
85
|
#
|
52
86
|
# Find orphaned digests
|
53
87
|
#
|
54
88
|
#
|
55
89
|
# @return [Array<String>] an array of orphaned digests
|
56
90
|
#
|
57
|
-
def orphans
|
58
|
-
|
59
|
-
|
91
|
+
def orphans # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
|
92
|
+
page = 0
|
93
|
+
per = reaper_count * 2
|
94
|
+
orphans = []
|
95
|
+
results = conn.zrange(digests.key, page * per, (page + 1) * per)
|
96
|
+
|
97
|
+
while results.size.positive?
|
98
|
+
results.each do |digest|
|
99
|
+
break if timeout?
|
100
|
+
next if belongs_to_job?(digest)
|
101
|
+
|
102
|
+
orphans << digest
|
103
|
+
break if orphans.size >= reaper_count
|
104
|
+
end
|
60
105
|
|
61
|
-
|
62
|
-
break if
|
106
|
+
break if timeout?
|
107
|
+
break if orphans.size >= reaper_count
|
108
|
+
|
109
|
+
page += 1
|
110
|
+
results = conn.zrange(digests.key, page * per, (page + 1) * per)
|
63
111
|
end
|
112
|
+
|
113
|
+
orphans
|
114
|
+
end
|
115
|
+
|
116
|
+
def timeout?
|
117
|
+
elapsed_ms >= timeout_ms
|
118
|
+
end
|
119
|
+
|
120
|
+
def elapsed_ms
|
121
|
+
time_source.call - start_source
|
64
122
|
end
|
65
123
|
|
66
124
|
#
|
@@ -122,18 +180,18 @@ module SidekiqUniqueJobs
|
|
122
180
|
|
123
181
|
def active?(digest) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
124
182
|
Sidekiq.redis do |conn|
|
125
|
-
procs = conn.
|
183
|
+
procs = conn.sscan("processes").to_a
|
126
184
|
return false if procs.empty?
|
127
185
|
|
128
186
|
procs.sort.each do |key|
|
129
|
-
valid, workers = conn.pipelined do
|
187
|
+
valid, workers = conn.pipelined do |pipeline|
|
130
188
|
# TODO: Remove the if statement in the future
|
131
|
-
if
|
132
|
-
|
189
|
+
if pipeline.respond_to?(:exists?)
|
190
|
+
pipeline.exists?(key)
|
133
191
|
else
|
134
|
-
|
192
|
+
pipeline.exists(key)
|
135
193
|
end
|
136
|
-
|
194
|
+
pipeline.hgetall("#{key}:work")
|
137
195
|
end
|
138
196
|
|
139
197
|
next unless valid
|
@@ -173,7 +231,7 @@ module SidekiqUniqueJobs
|
|
173
231
|
# @yield queues one at a time
|
174
232
|
#
|
175
233
|
def queues(conn, &block)
|
176
|
-
conn.
|
234
|
+
conn.sscan("queues").each(&block)
|
177
235
|
end
|
178
236
|
|
179
237
|
def entries(conn, queue, &block) # rubocop:disable Metrics/MethodLength
|
@@ -185,6 +243,7 @@ module SidekiqUniqueJobs
|
|
185
243
|
|
186
244
|
loop do
|
187
245
|
range_start = (page * page_size) - deleted_size
|
246
|
+
|
188
247
|
range_end = range_start + page_size - 1
|
189
248
|
entries = conn.lrange(queue_key, range_start, range_end)
|
190
249
|
page += 1
|
@@ -194,7 +253,26 @@ module SidekiqUniqueJobs
|
|
194
253
|
entries.each(&block)
|
195
254
|
|
196
255
|
deleted_size = initial_size - conn.llen(queue_key)
|
256
|
+
|
257
|
+
# The queue is growing, not shrinking, just keep looping
|
258
|
+
deleted_size = 0 if deleted_size.negative?
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
# If sidekiq queues are very full, it becomes highly inefficient for the reaper
|
263
|
+
# because it must check every queued job to verify a digest is safe to delete
|
264
|
+
# The reaper checks queued jobs in batches of 50, adding 2 reads per digest
|
265
|
+
# With a queue length of 1,000 jobs, that's over 20 extra reads per digest.
|
266
|
+
def queues_very_full?
|
267
|
+
total_queue_size = 0
|
268
|
+
Sidekiq.redis do |conn|
|
269
|
+
queues(conn) do |queue|
|
270
|
+
total_queue_size += conn.llen("queue:#{queue}")
|
271
|
+
|
272
|
+
return true if total_queue_size > MAX_QUEUE_LENGTH
|
273
|
+
end
|
197
274
|
end
|
275
|
+
false
|
198
276
|
end
|
199
277
|
|
200
278
|
#
|
@@ -208,8 +286,9 @@ module SidekiqUniqueJobs
|
|
208
286
|
# @return [false] when missing
|
209
287
|
#
|
210
288
|
def in_sorted_set?(key, digest)
|
211
|
-
conn.
|
289
|
+
conn.zscan(key, match: "*#{digest}*", count: 1).to_a.any?
|
212
290
|
end
|
213
291
|
end
|
292
|
+
# rubocop:enable Metrics/ClassLength
|
214
293
|
end
|
215
294
|
end
|
@@ -8,6 +8,13 @@ module SidekiqUniqueJobs
|
|
8
8
|
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
9
9
|
#
|
10
10
|
class SortedSet < Entity
|
11
|
+
#
|
12
|
+
# @return [Integer] the number of matches to return by default
|
13
|
+
DEFAULT_COUNT = 1_000
|
14
|
+
#
|
15
|
+
# @return [String] the default pattern to use for matching
|
16
|
+
SCAN_PATTERN = "*"
|
17
|
+
|
11
18
|
#
|
12
19
|
# Return entries for this sorted set
|
13
20
|
#
|
@@ -17,7 +24,7 @@ module SidekiqUniqueJobs
|
|
17
24
|
# @return [Hash] when given with_scores: true
|
18
25
|
#
|
19
26
|
def entries(with_scores: true)
|
20
|
-
entrys = redis { |conn| conn.zrange(key, 0, -1,
|
27
|
+
entrys = redis { |conn| conn.zrange(key, 0, -1, withscores: with_scores) }
|
21
28
|
return entrys unless with_scores
|
22
29
|
|
23
30
|
entrys.each_with_object({}) { |pair, hash| hash[pair[0]] = pair[1] }
|
@@ -33,7 +40,7 @@ module SidekiqUniqueJobs
|
|
33
40
|
def add(values)
|
34
41
|
redis do |conn|
|
35
42
|
if values.is_a?(Array)
|
36
|
-
conn.zadd(key, values)
|
43
|
+
conn.zadd(key, *values)
|
37
44
|
else
|
38
45
|
conn.zadd(key, now_f, values)
|
39
46
|
end
|
@@ -54,14 +54,9 @@ module SidekiqUniqueJobs
|
|
54
54
|
# Only used to reduce a little bit of duplication
|
55
55
|
# @see call_script
|
56
56
|
def do_call(file_name, conn, keys, argv)
|
57
|
-
argv = argv.dup.
|
58
|
-
|
59
|
-
|
60
|
-
max_history,
|
61
|
-
file_name,
|
62
|
-
redis_version,
|
63
|
-
])
|
64
|
-
Script.execute(file_name, conn, keys: keys, argv: argv)
|
57
|
+
argv = argv.dup.push(now_f, debug_lua, max_history, file_name, redis_version)
|
58
|
+
|
59
|
+
Script.execute(file_name, conn, keys: keys, argv: normalize_argv(argv))
|
65
60
|
end
|
66
61
|
|
67
62
|
#
|
@@ -122,6 +117,17 @@ module SidekiqUniqueJobs
|
|
122
117
|
def redis_version
|
123
118
|
SidekiqUniqueJobs.config.redis_version
|
124
119
|
end
|
120
|
+
|
121
|
+
def normalize_argv(argv)
|
122
|
+
argv.each_with_index do |item, index|
|
123
|
+
case item
|
124
|
+
when FalseClass, NilClass
|
125
|
+
argv[index] = 0
|
126
|
+
when TrueClass
|
127
|
+
argv[index] = 1
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
125
131
|
end
|
126
132
|
end
|
127
133
|
end
|
@@ -17,7 +17,7 @@ module SidekiqUniqueJobs # rubocop:disable Metrics/ModuleLength
|
|
17
17
|
# @return [SidekiqUniqueJobs::Config] the gem configuration
|
18
18
|
#
|
19
19
|
def config
|
20
|
-
@config ||= reset!
|
20
|
+
@config ||= reset! # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
|
21
21
|
end
|
22
22
|
|
23
23
|
#
|
@@ -71,6 +71,16 @@ module SidekiqUniqueJobs # rubocop:disable Metrics/ModuleLength
|
|
71
71
|
config.logger = other
|
72
72
|
end
|
73
73
|
|
74
|
+
#
|
75
|
+
# Check if logging is enabled
|
76
|
+
#
|
77
|
+
#
|
78
|
+
# @return [true, false]
|
79
|
+
#
|
80
|
+
def logging?
|
81
|
+
config.logger_enabled
|
82
|
+
end
|
83
|
+
|
74
84
|
#
|
75
85
|
# Temporarily use another configuration and reset to the old config after yielding
|
76
86
|
#
|
@@ -98,7 +108,7 @@ module SidekiqUniqueJobs # rubocop:disable Metrics/ModuleLength
|
|
98
108
|
# @return [SidekiqUniqueJobs::Config] a default gem configuration
|
99
109
|
#
|
100
110
|
def reset!
|
101
|
-
@config = SidekiqUniqueJobs::Config.default
|
111
|
+
@config = SidekiqUniqueJobs::Config.default # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
|
102
112
|
end
|
103
113
|
|
104
114
|
#
|
@@ -188,7 +198,7 @@ module SidekiqUniqueJobs # rubocop:disable Metrics/ModuleLength
|
|
188
198
|
# @return [String] a string like `5.0.2`
|
189
199
|
#
|
190
200
|
def fetch_redis_version
|
191
|
-
Sidekiq.redis_info["redis_version"]
|
201
|
+
Sidekiq.default_configuration.redis_info["redis_version"]
|
192
202
|
end
|
193
203
|
|
194
204
|
#
|
@@ -278,7 +288,7 @@ module SidekiqUniqueJobs # rubocop:disable Metrics/ModuleLength
|
|
278
288
|
# @return [Reflections]
|
279
289
|
#
|
280
290
|
def reflections
|
281
|
-
@reflections ||= Reflections.new
|
291
|
+
@reflections ||= Reflections.new # rubocop:disable ThreadSafety/InstanceVariableInClassMethod
|
282
292
|
end
|
283
293
|
|
284
294
|
#
|
@@ -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
|
11
|
-
|
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
|
17
|
-
return {} unless
|
21
|
+
def job_options
|
22
|
+
return {} unless sidekiq_job_class?
|
18
23
|
|
19
|
-
|
24
|
+
job_class.get_sidekiq_options.deep_stringify_keys
|
20
25
|
end
|
21
26
|
|
22
27
|
# Tests that the
|
23
|
-
# @return [true] if
|
24
|
-
# @return [false] if
|
25
|
-
def
|
26
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@
|
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 @
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
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
|
62
|
-
Sidekiq.
|
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
|