sidekiq-unique-jobs 7.1.26 → 7.1.27
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 +31 -0
- data/README.md +3 -1
- data/lib/sidekiq_unique_jobs/config.rb +5 -0
- data/lib/sidekiq_unique_jobs/locksmith.rb +11 -2
- data/lib/sidekiq_unique_jobs/logging.rb +14 -0
- data/lib/sidekiq_unique_jobs/lua/lock_until_expired.lua +92 -0
- data/lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb +10 -0
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6c5acd562db0da327940682a24bf4c28793a61ffb9904c3f480352253676b4e
|
4
|
+
data.tar.gz: 1673f51ceb70a1e6f37e60a411a93fe6ed9a05091a6e044b38283f2dbc93bbaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90dc8a981cd53213457bec790de3460823317666693ba56d5bc8d4f890a8a376e125ba5034f438109f1e883a847c09341634aa0bc8d509ed0d21534f53f49b4b
|
7
|
+
data.tar.gz: b4d4e314415706035afb5b3b078be70acb762134aa75e89be87d8e76bed0cdafec1e27ec9d303cae596b41ad5e504dccc01dd989256cd4272e29ebbb47e8f4cf
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [Unreleased](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/HEAD)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.26...HEAD)
|
6
|
+
|
7
|
+
**Closed issues:**
|
8
|
+
|
9
|
+
- Memory bloat / dangling keys / reaper not cleaning orphans [\#637](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/637)
|
10
|
+
|
11
|
+
## [v7.1.26](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.26) (2022-07-28)
|
12
|
+
|
13
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.25...v7.1.26)
|
14
|
+
|
15
|
+
**Implemented enhancements:**
|
16
|
+
|
17
|
+
- Fix\(until\_expired\): Fix test and implementation [\#725](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/725) ([mhenrixon](https://github.com/mhenrixon))
|
18
|
+
|
19
|
+
**Fixed bugs:**
|
20
|
+
|
21
|
+
- Fix\(until\_and\_while\_executing\): Improve timeouts slightly [\#728](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/728) ([mhenrixon](https://github.com/mhenrixon))
|
22
|
+
- Fix\(unlock\): Delete primed keys on last entry [\#726](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/726) ([mhenrixon](https://github.com/mhenrixon))
|
23
|
+
|
24
|
+
**Merged pull requests:**
|
25
|
+
|
26
|
+
- Ensure batch delete removes expiring locks [\#724](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/724) ([francesmcmullin](https://github.com/francesmcmullin))
|
27
|
+
- Chore: Update dependencies [\#722](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/722) ([mhenrixon](https://github.com/mhenrixon))
|
28
|
+
- Move until\_expired digests to separate zset [\#721](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/721) ([francesmcmullin](https://github.com/francesmcmullin))
|
29
|
+
- Avoid skipping ranges when looping through queues [\#720](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/720) ([francesmcmullin](https://github.com/francesmcmullin))
|
30
|
+
- Bump actions/checkout from 2 to 3 [\#718](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/718) ([dependabot[bot]](https://github.com/apps/dependabot))
|
31
|
+
- Add Dependabot for GitHub Actions [\#717](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/717) ([petergoldstein](https://github.com/petergoldstein))
|
32
|
+
- Fix Sidekiq::Worker.clear\_all override not being applied [\#714](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/714) ([dsander](https://github.com/dsander))
|
33
|
+
|
3
34
|
## [v7.1.25](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.25) (2022-06-13)
|
4
35
|
|
5
36
|
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.24...v7.1.25)
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ Want to show me some ❤️ for the hard work I do on this gem? You can use the
|
|
31
31
|
- [raise](#raise)
|
32
32
|
- [reject](#reject)
|
33
33
|
- [replace](#replace)
|
34
|
-
- [
|
34
|
+
- [reschedule](#reschedule)
|
35
35
|
- [Custom Strategies](#custom-strategies)
|
36
36
|
- [3 Cleanup Dead Locks](#3-cleanup-dead-locks)
|
37
37
|
- [Debugging](#debugging)
|
@@ -610,6 +610,7 @@ This has been probably the most confusing part of this gem. People get really co
|
|
610
610
|
```ruby
|
611
611
|
SidekiqUniqueJobs.configure do |config|
|
612
612
|
config.enabled = !Rails.env.test?
|
613
|
+
config.logger_enabled = !Rails.env.test?
|
613
614
|
end
|
614
615
|
```
|
615
616
|
|
@@ -736,6 +737,7 @@ Configure SidekiqUniqueJobs in an initializer or the sidekiq initializer on appl
|
|
736
737
|
```ruby
|
737
738
|
SidekiqUniqueJobs.configure do |config|
|
738
739
|
config.logger = Sidekiq.logger # default, change at your own discretion
|
740
|
+
config.logger_enabled = true # default, disable for test environments
|
739
741
|
config.debug_lua = false # Turn on when debugging
|
740
742
|
config.lock_info = false # Turn on when debugging
|
741
743
|
config.lock_ttl = 600 # Expire locks after 10 minutes
|
@@ -8,6 +8,7 @@ module SidekiqUniqueJobs
|
|
8
8
|
:enabled,
|
9
9
|
:lock_prefix,
|
10
10
|
:logger,
|
11
|
+
:logger_enabled,
|
11
12
|
:locks,
|
12
13
|
:strategies,
|
13
14
|
:debug_lua,
|
@@ -91,6 +92,9 @@ module SidekiqUniqueJobs
|
|
91
92
|
# @return [nil]
|
92
93
|
LOCK_TTL = nil
|
93
94
|
#
|
95
|
+
# @return [true,false] by default false (don't disable logger)
|
96
|
+
LOGGER_ENABLED = true
|
97
|
+
#
|
94
98
|
# @return [true] by default the gem is enabled
|
95
99
|
ENABLED = true
|
96
100
|
#
|
@@ -180,6 +184,7 @@ module SidekiqUniqueJobs
|
|
180
184
|
ENABLED,
|
181
185
|
PREFIX,
|
182
186
|
Sidekiq.logger,
|
187
|
+
LOGGER_ENABLED,
|
183
188
|
LOCKS,
|
184
189
|
STRATEGIES,
|
185
190
|
DEBUG_LUA,
|
@@ -298,10 +298,15 @@ module SidekiqUniqueJobs
|
|
298
298
|
# @api private
|
299
299
|
#
|
300
300
|
def brpoplpush(conn, wait)
|
301
|
+
# passing timeout 0 to brpoplpush causes it to block indefinitely
|
301
302
|
raise InvalidArgument, "wait must be an integer" unless wait.is_a?(Integer)
|
303
|
+
return conn.brpoplpush(key.queued, key.primed, wait) if conn.class.to_s == "Redis::Namespace"
|
302
304
|
|
303
|
-
|
304
|
-
|
305
|
+
if VersionCheck.satisfied?(redis_version, ">= 6.2.0") && conn.respond_to?(:blmove)
|
306
|
+
conn.blmove(key.queued, key.primed, "RIGHT", "LEFT", timeout: wait)
|
307
|
+
else
|
308
|
+
conn.brpoplpush(key.queued, key.primed, timeout: wait)
|
309
|
+
end
|
305
310
|
end
|
306
311
|
|
307
312
|
#
|
@@ -370,5 +375,9 @@ module SidekiqUniqueJobs
|
|
370
375
|
TIME => now_f,
|
371
376
|
)
|
372
377
|
end
|
378
|
+
|
379
|
+
def redis_version
|
380
|
+
@redis_version ||= SidekiqUniqueJobs.config.redis_version
|
381
|
+
end
|
373
382
|
end
|
374
383
|
end
|
@@ -30,6 +30,8 @@ module SidekiqUniqueJobs
|
|
30
30
|
# @yield [String, Exception] the message or exception to use for log message
|
31
31
|
#
|
32
32
|
def log_debug(message_or_exception = nil, item = nil, &block)
|
33
|
+
return unless logging?
|
34
|
+
|
33
35
|
message = build_message(message_or_exception, item)
|
34
36
|
logger.debug(message, &block)
|
35
37
|
nil
|
@@ -45,6 +47,8 @@ module SidekiqUniqueJobs
|
|
45
47
|
# @yield [String, Exception] the message or exception to use for log message
|
46
48
|
#
|
47
49
|
def log_info(message_or_exception = nil, item = nil, &block)
|
50
|
+
return unless logging?
|
51
|
+
|
48
52
|
message = build_message(message_or_exception, item)
|
49
53
|
logger.info(message, &block)
|
50
54
|
nil
|
@@ -60,6 +64,8 @@ module SidekiqUniqueJobs
|
|
60
64
|
# @yield [String, Exception] the message or exception to use for log message
|
61
65
|
#
|
62
66
|
def log_warn(message_or_exception = nil, item = nil, &block)
|
67
|
+
return unless logging?
|
68
|
+
|
63
69
|
message = build_message(message_or_exception, item)
|
64
70
|
logger.warn(message, &block)
|
65
71
|
nil
|
@@ -75,6 +81,8 @@ module SidekiqUniqueJobs
|
|
75
81
|
# @yield [String, Exception] the message or exception to use for log message
|
76
82
|
#
|
77
83
|
def log_error(message_or_exception = nil, item = nil, &block)
|
84
|
+
return unless logging?
|
85
|
+
|
78
86
|
message = build_message(message_or_exception, item)
|
79
87
|
logger.error(message, &block)
|
80
88
|
nil
|
@@ -90,6 +98,8 @@ module SidekiqUniqueJobs
|
|
90
98
|
# @yield [String, Exception] the message or exception to use for log message
|
91
99
|
#
|
92
100
|
def log_fatal(message_or_exception = nil, item = nil, &block)
|
101
|
+
return unless logging?
|
102
|
+
|
93
103
|
message = build_message(message_or_exception, item)
|
94
104
|
logger.fatal(message, &block)
|
95
105
|
|
@@ -218,5 +228,9 @@ module SidekiqUniqueJobs
|
|
218
228
|
|
219
229
|
yield
|
220
230
|
end
|
231
|
+
|
232
|
+
def logging?
|
233
|
+
SidekiqUniqueJobs.logging?
|
234
|
+
end
|
221
235
|
end
|
222
236
|
end
|
@@ -0,0 +1,92 @@
|
|
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
|
+
local expiring_digests = KEYS[8]
|
10
|
+
-------- END keys ---------
|
11
|
+
|
12
|
+
|
13
|
+
-------- BEGIN lock arguments ---------
|
14
|
+
local job_id = ARGV[1]
|
15
|
+
local pttl = tonumber(ARGV[2])
|
16
|
+
local lock_type = ARGV[3]
|
17
|
+
local limit = tonumber(ARGV[4])
|
18
|
+
-------- END lock arguments -----------
|
19
|
+
|
20
|
+
|
21
|
+
-------- BEGIN injected arguments --------
|
22
|
+
local current_time = tonumber(ARGV[5])
|
23
|
+
local debug_lua = ARGV[6] == "true"
|
24
|
+
local max_history = tonumber(ARGV[7])
|
25
|
+
local script_name = tostring(ARGV[8]) .. ".lua"
|
26
|
+
local redisversion = ARGV[9]
|
27
|
+
--------- END injected arguments ---------
|
28
|
+
|
29
|
+
|
30
|
+
-------- BEGIN local functions --------
|
31
|
+
<%= include_partial "shared/_common.lua" %>
|
32
|
+
---------- END local functions ----------
|
33
|
+
|
34
|
+
|
35
|
+
--------- BEGIN lock.lua ---------
|
36
|
+
log_debug("BEGIN lock digest:", digest, "job_id:", job_id)
|
37
|
+
|
38
|
+
if redis.call("HEXISTS", locked, job_id) == 1 then
|
39
|
+
log_debug(locked, "already locked with job_id:", job_id)
|
40
|
+
log("Duplicate")
|
41
|
+
|
42
|
+
log_debug("LREM", queued, -1, job_id)
|
43
|
+
redis.call("LREM", queued, -1, job_id)
|
44
|
+
|
45
|
+
log_debug("LREM", primed, 1, job_id)
|
46
|
+
redis.call("LREM", primed, 1, job_id)
|
47
|
+
|
48
|
+
return job_id
|
49
|
+
end
|
50
|
+
|
51
|
+
local locked_count = redis.call("HLEN", locked)
|
52
|
+
local within_limit = limit > locked_count
|
53
|
+
local limit_exceeded = not within_limit
|
54
|
+
|
55
|
+
if limit_exceeded then
|
56
|
+
log_debug("Limit exceeded:", digest, "(", locked_count, "of", limit, ")")
|
57
|
+
log("Limited")
|
58
|
+
return nil
|
59
|
+
end
|
60
|
+
|
61
|
+
log_debug("ZADD", expiring_digests, current_time + pttl, digest)
|
62
|
+
redis.call("ZADD", expiring_digests, current_time + pttl, digest)
|
63
|
+
|
64
|
+
log_debug("HSET", locked, job_id, current_time)
|
65
|
+
redis.call("HSET", locked, job_id, current_time)
|
66
|
+
|
67
|
+
log_debug("LREM", queued, -1, job_id)
|
68
|
+
redis.call("LREM", queued, -1, job_id)
|
69
|
+
|
70
|
+
log_debug("LREM", primed, 1, job_id)
|
71
|
+
redis.call("LREM", primed, 1, job_id)
|
72
|
+
|
73
|
+
-- The Sidekiq client sets pttl
|
74
|
+
log_debug("PEXPIRE", digest, pttl)
|
75
|
+
redis.call("PEXPIRE", digest, pttl)
|
76
|
+
|
77
|
+
log_debug("PEXPIRE", locked, pttl)
|
78
|
+
redis.call("PEXPIRE", locked, pttl)
|
79
|
+
|
80
|
+
log_debug("PEXPIRE", info, pttl)
|
81
|
+
redis.call("PEXPIRE", info, pttl)
|
82
|
+
|
83
|
+
log_debug("PEXPIRE", queued, 1000)
|
84
|
+
redis.call("PEXPIRE", queued, 1000)
|
85
|
+
|
86
|
+
log_debug("PEXPIRE", primed, 1000)
|
87
|
+
redis.call("PEXPIRE", primed, 1000)
|
88
|
+
|
89
|
+
log("Locked")
|
90
|
+
log_debug("END lock digest:", digest, "job_id:", job_id)
|
91
|
+
return job_id
|
92
|
+
---------- END lock.lua ----------
|
@@ -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
|
#
|
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.27
|
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-07-
|
11
|
+
date: 2022-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: brpoplpush-redis_script
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- lib/sidekiq_unique_jobs/lua/delete_job_by_digest.lua
|
146
146
|
- lib/sidekiq_unique_jobs/lua/find_digest_in_queues.lua
|
147
147
|
- lib/sidekiq_unique_jobs/lua/lock.lua
|
148
|
+
- lib/sidekiq_unique_jobs/lua/lock_until_expired.lua
|
148
149
|
- lib/sidekiq_unique_jobs/lua/locked.lua
|
149
150
|
- lib/sidekiq_unique_jobs/lua/queue.lua
|
150
151
|
- lib/sidekiq_unique_jobs/lua/reap_orphans.lua
|