sidekiq-unique-jobs 6.0.25 → 7.0.0.beta2
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 +155 -20
- data/README.md +349 -112
- data/lib/sidekiq-unique-jobs.rb +2 -0
- data/lib/sidekiq_unique_jobs.rb +43 -6
- data/lib/sidekiq_unique_jobs/batch_delete.rb +121 -0
- data/lib/sidekiq_unique_jobs/changelog.rb +71 -0
- data/lib/sidekiq_unique_jobs/cli.rb +20 -29
- data/lib/sidekiq_unique_jobs/config.rb +193 -0
- data/lib/sidekiq_unique_jobs/connection.rb +5 -4
- data/lib/sidekiq_unique_jobs/constants.rb +36 -24
- data/lib/sidekiq_unique_jobs/core_ext.rb +38 -0
- data/lib/sidekiq_unique_jobs/digests.rb +78 -93
- data/lib/sidekiq_unique_jobs/exceptions.rb +152 -8
- data/lib/sidekiq_unique_jobs/job.rb +3 -3
- data/lib/sidekiq_unique_jobs/json.rb +34 -0
- data/lib/sidekiq_unique_jobs/key.rb +93 -0
- data/lib/sidekiq_unique_jobs/lock.rb +295 -0
- data/lib/sidekiq_unique_jobs/lock/base_lock.rb +49 -43
- data/lib/sidekiq_unique_jobs/lock/client_validator.rb +28 -0
- data/lib/sidekiq_unique_jobs/lock/server_validator.rb +27 -0
- data/lib/sidekiq_unique_jobs/lock/until_and_while_executing.rb +8 -17
- data/lib/sidekiq_unique_jobs/lock/until_executed.rb +5 -5
- data/lib/sidekiq_unique_jobs/lock/until_expired.rb +1 -23
- data/lib/sidekiq_unique_jobs/lock/validator.rb +65 -0
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +12 -8
- data/lib/sidekiq_unique_jobs/lock/while_executing_reject.rb +1 -1
- data/lib/sidekiq_unique_jobs/lock_config.rb +95 -0
- data/lib/sidekiq_unique_jobs/lock_info.rb +68 -0
- data/lib/sidekiq_unique_jobs/locksmith.rb +255 -99
- data/lib/sidekiq_unique_jobs/logging.rb +148 -22
- data/lib/sidekiq_unique_jobs/logging/middleware_context.rb +44 -0
- data/lib/sidekiq_unique_jobs/lua/delete.lua +51 -0
- data/lib/sidekiq_unique_jobs/lua/delete_by_digest.lua +46 -0
- data/lib/sidekiq_unique_jobs/lua/delete_job_by_digest.lua +38 -0
- data/lib/sidekiq_unique_jobs/lua/find_digest_in_queues.lua +26 -0
- data/lib/sidekiq_unique_jobs/lua/find_digest_in_sorted_set.lua +24 -0
- data/lib/sidekiq_unique_jobs/lua/lock.lua +91 -0
- data/lib/sidekiq_unique_jobs/lua/locked.lua +35 -0
- data/lib/sidekiq_unique_jobs/lua/queue.lua +83 -0
- data/lib/sidekiq_unique_jobs/lua/reap_orphans.lua +86 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_common.lua +40 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_current_time.lua +8 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_delete_from_queue.lua +19 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_delete_from_sorted_set.lua +18 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_queues.lua +46 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_find_digest_in_sorted_set.lua +24 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_hgetall.lua +13 -0
- data/lib/sidekiq_unique_jobs/lua/shared/_upgrades.lua +3 -0
- data/lib/sidekiq_unique_jobs/lua/shared/find_digest_in_sorted_set.lua +24 -0
- data/lib/sidekiq_unique_jobs/lua/unlock.lua +99 -0
- data/lib/sidekiq_unique_jobs/lua/update_version.lua +40 -0
- data/lib/sidekiq_unique_jobs/lua/upgrade.lua +68 -0
- data/lib/sidekiq_unique_jobs/middleware.rb +62 -31
- data/lib/sidekiq_unique_jobs/middleware/client.rb +42 -0
- data/lib/sidekiq_unique_jobs/middleware/server.rb +27 -0
- data/lib/sidekiq_unique_jobs/normalizer.rb +3 -3
- data/lib/sidekiq_unique_jobs/on_conflict.rb +22 -9
- data/lib/sidekiq_unique_jobs/on_conflict/log.rb +8 -4
- data/lib/sidekiq_unique_jobs/on_conflict/reject.rb +59 -13
- data/lib/sidekiq_unique_jobs/on_conflict/replace.rb +42 -13
- data/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb +4 -4
- data/lib/sidekiq_unique_jobs/on_conflict/strategy.rb +24 -5
- data/lib/sidekiq_unique_jobs/options_with_fallback.rb +47 -23
- data/lib/sidekiq_unique_jobs/orphans/manager.rb +100 -0
- data/lib/sidekiq_unique_jobs/orphans/observer.rb +42 -0
- data/lib/sidekiq_unique_jobs/orphans/reaper.rb +201 -0
- data/lib/sidekiq_unique_jobs/profiler.rb +51 -0
- data/lib/sidekiq_unique_jobs/redis.rb +11 -0
- data/lib/sidekiq_unique_jobs/redis/entity.rb +94 -0
- data/lib/sidekiq_unique_jobs/redis/hash.rb +56 -0
- data/lib/sidekiq_unique_jobs/redis/list.rb +32 -0
- data/lib/sidekiq_unique_jobs/redis/set.rb +32 -0
- data/lib/sidekiq_unique_jobs/redis/sorted_set.rb +59 -0
- data/lib/sidekiq_unique_jobs/redis/string.rb +49 -0
- data/lib/sidekiq_unique_jobs/rspec/matchers.rb +19 -0
- data/lib/sidekiq_unique_jobs/rspec/matchers/have_valid_sidekiq_options.rb +43 -0
- data/lib/sidekiq_unique_jobs/{scripts.rb → script.rb} +43 -29
- data/lib/sidekiq_unique_jobs/script/caller.rb +125 -0
- data/lib/sidekiq_unique_jobs/script/template.rb +41 -0
- data/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +92 -65
- data/lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb +166 -28
- data/lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb +10 -11
- data/lib/sidekiq_unique_jobs/testing.rb +47 -15
- data/lib/sidekiq_unique_jobs/time_calculator.rb +103 -0
- data/lib/sidekiq_unique_jobs/timing.rb +58 -0
- data/lib/sidekiq_unique_jobs/unique_args.rb +19 -21
- data/lib/sidekiq_unique_jobs/unlockable.rb +11 -2
- data/lib/sidekiq_unique_jobs/update_version.rb +25 -0
- data/lib/sidekiq_unique_jobs/upgrade_locks.rb +151 -0
- data/lib/sidekiq_unique_jobs/version.rb +3 -1
- data/lib/sidekiq_unique_jobs/version_check.rb +1 -1
- data/lib/sidekiq_unique_jobs/web.rb +25 -19
- data/lib/sidekiq_unique_jobs/web/helpers.rb +98 -6
- data/lib/sidekiq_unique_jobs/web/views/lock.erb +108 -0
- data/lib/sidekiq_unique_jobs/web/views/locks.erb +52 -0
- data/lib/tasks/changelog.rake +4 -3
- metadata +70 -35
- data/lib/sidekiq_unique_jobs/client/middleware.rb +0 -56
- data/lib/sidekiq_unique_jobs/server/middleware.rb +0 -46
- data/lib/sidekiq_unique_jobs/timeout.rb +0 -8
- data/lib/sidekiq_unique_jobs/timeout/calculator.rb +0 -63
- data/lib/sidekiq_unique_jobs/util.rb +0 -103
- data/lib/sidekiq_unique_jobs/web/views/unique_digest.erb +0 -28
- data/lib/sidekiq_unique_jobs/web/views/unique_digests.erb +0 -46
- data/redis/acquire_lock.lua +0 -21
- data/redis/convert_legacy_lock.lua +0 -13
- data/redis/delete.lua +0 -14
- data/redis/delete_by_digest.lua +0 -23
- data/redis/delete_job_by_digest.lua +0 -60
- data/redis/lock.lua +0 -62
- data/redis/release_stale_locks.lua +0 -90
- data/redis/unlock.lua +0 -35
@@ -5,63 +5,189 @@ module SidekiqUniqueJobs
|
|
5
5
|
#
|
6
6
|
# @author Mikael Henriksson <mikael@zoolutions.se>
|
7
7
|
module Logging
|
8
|
-
|
8
|
+
def self.included(base)
|
9
|
+
base.send(:extend, self)
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# A convenience method for using the configured gem logger
|
14
|
+
#
|
15
|
+
# @see SidekiqUniqueJobs#.logger
|
16
|
+
#
|
17
|
+
# @return [Logger]
|
18
|
+
#
|
9
19
|
def logger
|
10
20
|
SidekiqUniqueJobs.logger
|
11
21
|
end
|
12
22
|
|
23
|
+
#
|
13
24
|
# Logs a message at debug level
|
14
|
-
#
|
15
|
-
# @
|
16
|
-
#
|
25
|
+
#
|
26
|
+
# @param [String, Exception] message_or_exception the message or exception to log
|
27
|
+
#
|
28
|
+
# @return [void]
|
29
|
+
#
|
30
|
+
# @yield [String, Exception] the message or exception to use for log message
|
31
|
+
#
|
17
32
|
def log_debug(message_or_exception = nil, &block)
|
18
33
|
logger.debug(message_or_exception, &block)
|
19
34
|
nil
|
20
35
|
end
|
21
36
|
|
37
|
+
#
|
22
38
|
# Logs a message at info level
|
23
|
-
#
|
24
|
-
# @
|
25
|
-
#
|
39
|
+
#
|
40
|
+
# @param [String, Exception] message_or_exception the message or exception to log
|
41
|
+
#
|
42
|
+
# @return [void]
|
43
|
+
#
|
44
|
+
# @yield [String, Exception] the message or exception to use for log message
|
45
|
+
#
|
26
46
|
def log_info(message_or_exception = nil, &block)
|
27
47
|
logger.info(message_or_exception, &block)
|
28
48
|
nil
|
29
49
|
end
|
30
50
|
|
51
|
+
#
|
31
52
|
# Logs a message at warn level
|
32
|
-
#
|
33
|
-
# @
|
34
|
-
#
|
53
|
+
#
|
54
|
+
# @param [String, Exception] message_or_exception the message or exception to log
|
55
|
+
#
|
56
|
+
# @return [void]
|
57
|
+
#
|
58
|
+
# @yield [String, Exception] the message or exception to use for log message
|
59
|
+
#
|
35
60
|
def log_warn(message_or_exception = nil, &block)
|
36
61
|
logger.warn(message_or_exception, &block)
|
37
62
|
nil
|
38
63
|
end
|
39
64
|
|
65
|
+
#
|
40
66
|
# Logs a message at error level
|
41
|
-
#
|
42
|
-
# @
|
43
|
-
#
|
67
|
+
#
|
68
|
+
# @param [String, Exception] message_or_exception the message or exception to log
|
69
|
+
#
|
70
|
+
# @return [void]
|
71
|
+
#
|
72
|
+
# @yield [String, Exception] the message or exception to use for log message
|
73
|
+
#
|
44
74
|
def log_error(message_or_exception = nil, &block)
|
45
75
|
logger.error(message_or_exception, &block)
|
46
76
|
nil
|
47
77
|
end
|
48
78
|
|
79
|
+
#
|
49
80
|
# Logs a message at fatal level
|
50
|
-
#
|
51
|
-
# @
|
52
|
-
#
|
81
|
+
#
|
82
|
+
# @param [String, Exception] message_or_exception the message or exception to log
|
83
|
+
#
|
84
|
+
# @return [void]
|
85
|
+
#
|
86
|
+
# @yield [String, Exception] the message or exception to use for log message
|
87
|
+
#
|
53
88
|
def log_fatal(message_or_exception = nil, &block)
|
54
89
|
logger.fatal(message_or_exception, &block)
|
55
90
|
nil
|
56
91
|
end
|
57
92
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
93
|
+
#
|
94
|
+
# Wraps the middleware logic with context aware logging
|
95
|
+
#
|
96
|
+
#
|
97
|
+
# @return [void]
|
98
|
+
#
|
99
|
+
# @yieldreturn [void] yield to the middleware instance
|
100
|
+
#
|
101
|
+
def with_logging_context
|
102
|
+
with_configured_loggers_context do
|
103
|
+
return yield
|
64
104
|
end
|
105
|
+
|
106
|
+
nil # Need to make sure we don't return anything here
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# Attempt to setup context aware logging for the given logger
|
111
|
+
#
|
112
|
+
#
|
113
|
+
# @return [void]
|
114
|
+
#
|
115
|
+
# @yield
|
116
|
+
#
|
117
|
+
def with_configured_loggers_context
|
118
|
+
logger_method.call(logging_context) { yield }
|
119
|
+
end
|
120
|
+
|
121
|
+
#
|
122
|
+
# Setup some variables to add to each log line
|
123
|
+
#
|
124
|
+
#
|
125
|
+
# @return [Hash] the context to use for each log line
|
126
|
+
#
|
127
|
+
def logging_context
|
128
|
+
raise NotImplementedError, "#{__method__} needs to be implemented in #{self.class}"
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
#
|
134
|
+
# A memoized method to use for setting up a logging context
|
135
|
+
#
|
136
|
+
#
|
137
|
+
# @return [proc] the method to call
|
138
|
+
#
|
139
|
+
def logger_method
|
140
|
+
@logger_method ||= sidekiq_context_method
|
141
|
+
@logger_method ||= sidekiq_logger_context_method
|
142
|
+
@logger_method ||= sidekiq_logging_context_method
|
143
|
+
@logger_method ||= no_sidekiq_context_method
|
144
|
+
end
|
145
|
+
|
146
|
+
#
|
147
|
+
# Checks if the logger respond to `with_context`.
|
148
|
+
#
|
149
|
+
# @note only used to remove the need for explicitly ignoring manual dispatch in other places.
|
150
|
+
#
|
151
|
+
#
|
152
|
+
# @return [true,false]
|
153
|
+
#
|
154
|
+
def logger_respond_to_with_context?
|
155
|
+
logger.respond_to?(:with_context)
|
156
|
+
end
|
157
|
+
|
158
|
+
#
|
159
|
+
# Checks if the logger context takes a hash argument
|
160
|
+
#
|
161
|
+
# @note only used to remove the need for explicitly ignoring manual dispatch in other places.
|
162
|
+
#
|
163
|
+
#
|
164
|
+
# @return [true,false]
|
165
|
+
#
|
166
|
+
def logger_context_hash?
|
167
|
+
defined?(Sidekiq::Context) || logger_respond_to_with_context?
|
168
|
+
end
|
169
|
+
|
170
|
+
def sidekiq_context_method
|
171
|
+
Sidekiq::Context.method(:with) if defined?(Sidekiq::Context)
|
172
|
+
end
|
173
|
+
|
174
|
+
def sidekiq_logger_context_method
|
175
|
+
logger.method(:with_context) if logger_respond_to_with_context?
|
176
|
+
end
|
177
|
+
|
178
|
+
def sidekiq_logging_context_method
|
179
|
+
Sidekiq::Logging.method(:with_context) if defined?(Sidekiq::Logging)
|
180
|
+
end
|
181
|
+
|
182
|
+
def no_sidekiq_context_method
|
183
|
+
method(:fake_logger_context)
|
184
|
+
end
|
185
|
+
|
186
|
+
def fake_logger_context(_context)
|
187
|
+
logger.warn "Don't know how to setup the logging context. Please open a feature request:" \
|
188
|
+
" https://github.com/mhenrixon/sidekiq-unique-jobs/issues/new?template=feature_request.md"
|
189
|
+
|
190
|
+
yield
|
65
191
|
end
|
66
192
|
end
|
67
193
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SidekiqUniqueJobs
|
4
|
+
#
|
5
|
+
# Provides the sidekiq middleware that makes the gem work
|
6
|
+
#
|
7
|
+
# @author Mikael Henriksson <mikael@zoolutions.se>
|
8
|
+
#
|
9
|
+
module Logging
|
10
|
+
#
|
11
|
+
# Context aware logging for Sidekiq Middlewares
|
12
|
+
#
|
13
|
+
# @author Mikael Henriksson <mikael@zoolutions.se>
|
14
|
+
#
|
15
|
+
module Middleware
|
16
|
+
include Logging
|
17
|
+
|
18
|
+
def self.included(base)
|
19
|
+
base.class_eval do
|
20
|
+
extend Logging::Middleware
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Provides a logging context for Sidekiq Middlewares
|
26
|
+
#
|
27
|
+
#
|
28
|
+
# @return [Hash] when logger responds to `:with_context`
|
29
|
+
# @return [String] when logger does not responds to `:with_context`
|
30
|
+
#
|
31
|
+
def logging_context
|
32
|
+
middleware = is_a?(SidekiqUniqueJobs::Middleware::Client) ? :client : :server
|
33
|
+
digest = item[UNIQUE_DIGEST]
|
34
|
+
lock_type = item[LOCK]
|
35
|
+
|
36
|
+
if logger_context_hash?
|
37
|
+
{ "uniquejobs" => middleware, lock_type => digest }
|
38
|
+
else
|
39
|
+
"uniquejobs-#{middleware} #{"DIG-#{digest}" if digest}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
-------- BEGIN keys ---------
|
2
|
+
local digest = KEYS[1]
|
3
|
+
local queued = KEYS[2]
|
4
|
+
local primed = KEYS[3]
|
5
|
+
local locked = KEYS[4]
|
6
|
+
local info = KEYS[5]
|
7
|
+
local changelog = KEYS[6]
|
8
|
+
local digests = KEYS[7]
|
9
|
+
-------- END keys ---------
|
10
|
+
|
11
|
+
-------- BEGIN lock arguments ---------
|
12
|
+
local job_id = ARGV[1]
|
13
|
+
local pttl = tonumber(ARGV[2])
|
14
|
+
local lock_type = ARGV[3]
|
15
|
+
local limit = tonumber(ARGV[4])
|
16
|
+
-------- END lock arguments -----------
|
17
|
+
|
18
|
+
-------- BEGIN injected arguments --------
|
19
|
+
local current_time = tonumber(ARGV[5])
|
20
|
+
local debug_lua = tostring(ARGV[6]) == "true"
|
21
|
+
local max_history = tonumber(ARGV[7])
|
22
|
+
local script_name = tostring(ARGV[8]) .. ".lua"
|
23
|
+
local redisversion = tostring(ARGV[9])
|
24
|
+
--------- END injected arguments ---------
|
25
|
+
|
26
|
+
-------- BEGIN local functions --------
|
27
|
+
<%= include_partial "shared/_common.lua" %>
|
28
|
+
---------- END local functions ----------
|
29
|
+
|
30
|
+
|
31
|
+
-------- BEGIN delete.lua --------
|
32
|
+
log_debug("BEGIN delete", digest)
|
33
|
+
|
34
|
+
local redis_version = toversion(redisversion)
|
35
|
+
local count = 0
|
36
|
+
local del_cmd = "DEL"
|
37
|
+
|
38
|
+
log_debug("ZREM", digests, digest)
|
39
|
+
count = count + redis.call("ZREM", digests, digest)
|
40
|
+
|
41
|
+
if redis_version["major"] >= 4 then del_cmd = "UNLINK"; end
|
42
|
+
|
43
|
+
log_debug(del_cmd, digest, queued, primed, locked, info)
|
44
|
+
count = count + redis.call(del_cmd, digest, queued, primed, locked, info)
|
45
|
+
|
46
|
+
|
47
|
+
log("Deleted (" .. count .. ") keys")
|
48
|
+
log_debug("END delete (" .. count .. ") keys for:", digest)
|
49
|
+
|
50
|
+
return count
|
51
|
+
-------- END delete.lua --------
|
@@ -0,0 +1,46 @@
|
|
1
|
+
-------- BEGIN keys ---------
|
2
|
+
local digest = KEYS[1]
|
3
|
+
local digests = KEYS[2]
|
4
|
+
-------- END keys ---------
|
5
|
+
|
6
|
+
-------- BEGIN injected arguments --------
|
7
|
+
local current_time = tonumber(ARGV[1])
|
8
|
+
local debug_lua = ARGV[2] == "true"
|
9
|
+
local max_history = tonumber(ARGV[3])
|
10
|
+
local script_name = tostring(ARGV[4]) .. ".lua"
|
11
|
+
local redisversion = tostring(ARGV[5])
|
12
|
+
--------- END injected arguments ---------
|
13
|
+
|
14
|
+
-------- BEGIN local functions --------
|
15
|
+
<%= include_partial "shared/_common.lua" %>
|
16
|
+
---------- END local functions ----------
|
17
|
+
|
18
|
+
-------- BEGIN Variables --------
|
19
|
+
local queued = digest .. ":QUEUED"
|
20
|
+
local primed = digest .. ":PRIMED"
|
21
|
+
local locked = digest .. ":LOCKED"
|
22
|
+
local run_digest = digest .. ":RUN"
|
23
|
+
local run_queued = digest .. ":RUN:QUEUED"
|
24
|
+
local run_primed = digest .. ":RUN:PRIMED"
|
25
|
+
local run_locked = digest .. ":RUN:LOCKED"
|
26
|
+
-------- END Variables --------
|
27
|
+
|
28
|
+
|
29
|
+
-------- BEGIN delete_by_digest.lua --------
|
30
|
+
local counter = 0
|
31
|
+
local redis_version = toversion(redisversion)
|
32
|
+
local del_cmd = "DEL"
|
33
|
+
|
34
|
+
log_debug("BEGIN delete_by_digest:", digest)
|
35
|
+
|
36
|
+
if redis_version["major"] >= 4 then del_cmd = "UNLINK"; end
|
37
|
+
|
38
|
+
log_debug(del_cmd, digest, queued, primed, locked, run_digest, run_queued, run_primed, run_locked)
|
39
|
+
counter = redis.call(del_cmd, digest, queued, primed, locked, run_digest, run_queued, run_primed, run_locked)
|
40
|
+
|
41
|
+
log_debug("ZREM", digests, digest)
|
42
|
+
redis.call("ZREM", digests, digest)
|
43
|
+
|
44
|
+
log_debug("END delete_by_digest:", digest, "(deleted " .. counter .. " keys)")
|
45
|
+
return counter
|
46
|
+
-------- END delete_by_digest.lua --------
|
@@ -0,0 +1,38 @@
|
|
1
|
+
-------- BEGIN keys ---------
|
2
|
+
local queue = KEYS[1]
|
3
|
+
local schedule_set = KEYS[2]
|
4
|
+
local retry_set = KEYS[3]
|
5
|
+
-------- END keys ---------
|
6
|
+
|
7
|
+
-------- BEGIN Arguments ---------
|
8
|
+
local digest = ARGV[1]
|
9
|
+
-------- END Arguments ---------
|
10
|
+
|
11
|
+
-------- BEGIN injected arguments --------
|
12
|
+
local current_time = tonumber(ARGV[2])
|
13
|
+
local debug_lua = ARGV[3] == "true"
|
14
|
+
local max_history = tonumber(ARGV[4])
|
15
|
+
local script_name = tostring(ARGV[5]) .. ".lua"
|
16
|
+
--------- END injected arguments ---------
|
17
|
+
|
18
|
+
-------- BEGIN local functions --------
|
19
|
+
<%= include_partial "shared/_common.lua" %>
|
20
|
+
<%= include_partial "shared/_delete_from_queue.lua" %>
|
21
|
+
<%= include_partial "shared/_delete_from_sorted_set.lua" %>
|
22
|
+
---------- END local functions ----------
|
23
|
+
|
24
|
+
|
25
|
+
-------- BEGIN delete_job_by_digest.lua --------
|
26
|
+
local result = delete_from_queue(queue, digest)
|
27
|
+
if result then
|
28
|
+
return result
|
29
|
+
end
|
30
|
+
|
31
|
+
result = delete_from_sorted_set(schedule_set, digest)
|
32
|
+
if result then
|
33
|
+
return result
|
34
|
+
end
|
35
|
+
|
36
|
+
result = delete_from_sorted_set(retry_set, digest)
|
37
|
+
return result
|
38
|
+
-------- END delete_job_by_digest.lua --------
|
@@ -0,0 +1,26 @@
|
|
1
|
+
-------- BEGIN keys ---------
|
2
|
+
local digest = KEYS[1]
|
3
|
+
-------- END keys ---------
|
4
|
+
|
5
|
+
-------- BEGIN injected arguments --------
|
6
|
+
local current_time = tonumber(ARGV[2])
|
7
|
+
local debug_lua = ARGV[3] == "true"
|
8
|
+
local max_history = tonumber(ARGV[4])
|
9
|
+
local script_name = tostring(ARGV[5]) .. ".lua"
|
10
|
+
--------- END injected arguments ---------
|
11
|
+
|
12
|
+
|
13
|
+
-------- BEGIN local functions --------
|
14
|
+
<%= include_partial "shared/_common.lua" %>
|
15
|
+
<%= include_partial "shared/_find_digest_in_queues.lua" %>
|
16
|
+
---------- END local functions ----------
|
17
|
+
|
18
|
+
|
19
|
+
-------- BEGIN delete_orphaned.lua --------
|
20
|
+
log_debug("BEGIN")
|
21
|
+
local result = find_digest_in_queues(digest)
|
22
|
+
log_debug("END")
|
23
|
+
if result and result ~= nil then
|
24
|
+
return result
|
25
|
+
end
|
26
|
+
-------- END delete_orphaned.lua --------
|
@@ -0,0 +1,24 @@
|
|
1
|
+
local function find_digest_in_sorted_set(name, digest)
|
2
|
+
local cursor = 0
|
3
|
+
local count = 5
|
4
|
+
local pattern = "*" .. digest .. "*"
|
5
|
+
local found = false
|
6
|
+
|
7
|
+
log_debug("searching in:", name,
|
8
|
+
"for digest:", digest,
|
9
|
+
"cursor:", cursor)
|
10
|
+
repeat
|
11
|
+
local pagination = redis.call("ZSCAN", name, cursor, "MATCH", pattern, "COUNT", count)
|
12
|
+
local next_cursor = pagination[1]
|
13
|
+
local items = pagination[2]
|
14
|
+
|
15
|
+
if #items > 0 then
|
16
|
+
log_debug("Found digest", digest, "in zset:", name)
|
17
|
+
found = true
|
18
|
+
end
|
19
|
+
|
20
|
+
cursor = next_cursor
|
21
|
+
until found == true or cursor == "0"
|
22
|
+
|
23
|
+
return found
|
24
|
+
end
|