sidekiq-unique-jobs 8.0.3 → 8.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +148 -1
- data/README.md +2 -4
- data/lib/sidekiq_unique_jobs/batch_delete.rb +1 -1
- data/lib/sidekiq_unique_jobs/changelog.rb +1 -1
- data/lib/sidekiq_unique_jobs/config.rb +4 -4
- data/lib/sidekiq_unique_jobs/constants.rb +1 -0
- data/lib/sidekiq_unique_jobs/digests.rb +46 -13
- data/lib/sidekiq_unique_jobs/job.rb +4 -4
- data/lib/sidekiq_unique_jobs/lock/base_lock.rb +1 -1
- data/lib/sidekiq_unique_jobs/lock/while_executing.rb +3 -0
- data/lib/sidekiq_unique_jobs/lock.rb +14 -11
- data/lib/sidekiq_unique_jobs/lock_config.rb +10 -4
- data/lib/sidekiq_unique_jobs/locksmith.rb +3 -3
- data/lib/sidekiq_unique_jobs/lua/unlock.lua +16 -9
- data/lib/sidekiq_unique_jobs/middleware/client.rb +1 -1
- data/lib/sidekiq_unique_jobs/middleware/server.rb +1 -1
- data/lib/sidekiq_unique_jobs/middleware.rb +5 -5
- data/lib/sidekiq_unique_jobs/on_conflict/replace.rb +1 -1
- data/lib/sidekiq_unique_jobs/on_conflict/reschedule.rb +5 -1
- data/lib/sidekiq_unique_jobs/orphans/manager.rb +8 -7
- data/lib/sidekiq_unique_jobs/orphans/reaper.rb +2 -1
- data/lib/sidekiq_unique_jobs/orphans/ruby_reaper.rb +26 -7
- data/lib/sidekiq_unique_jobs/redis/sorted_set.rb +12 -3
- data/lib/sidekiq_unique_jobs/script/caller.rb +1 -1
- data/lib/sidekiq_unique_jobs/script/client.rb +94 -0
- data/lib/sidekiq_unique_jobs/script/config.rb +68 -0
- data/lib/sidekiq_unique_jobs/script/dsl.rb +60 -0
- data/lib/sidekiq_unique_jobs/script/logging.rb +95 -0
- data/lib/sidekiq_unique_jobs/script/lua_error.rb +96 -0
- data/lib/sidekiq_unique_jobs/script/script.rb +75 -0
- data/lib/sidekiq_unique_jobs/script/scripts.rb +123 -0
- data/lib/sidekiq_unique_jobs/script/template.rb +41 -0
- data/lib/sidekiq_unique_jobs/script/timing.rb +35 -0
- data/lib/sidekiq_unique_jobs/script.rb +32 -1
- data/lib/sidekiq_unique_jobs/server.rb +2 -0
- data/lib/sidekiq_unique_jobs/sidekiq_unique_ext.rb +13 -35
- data/lib/sidekiq_unique_jobs/sidekiq_unique_jobs.rb +4 -4
- data/lib/sidekiq_unique_jobs/sidekiq_worker_methods.rb +3 -3
- data/lib/sidekiq_unique_jobs/testing.rb +4 -4
- data/lib/sidekiq_unique_jobs/version.rb +1 -1
- data/lib/sidekiq_unique_jobs/web/helpers.rb +3 -3
- data/lib/sidekiq_unique_jobs/web/views/changelogs.erb +1 -1
- data/lib/sidekiq_unique_jobs/web/views/lock.erb +2 -2
- data/lib/sidekiq_unique_jobs/web/views/locks.erb +1 -1
- data/lib/sidekiq_unique_jobs/web.rb +18 -17
- data/lib/sidekiq_unique_jobs.rb +5 -4
- metadata +12 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de442ce815fcfc00992295bd4160cfcf122815282e652cccca8c73ce1e62b351
|
4
|
+
data.tar.gz: f01d32c217f81f41abf34666c43acdddcb8148e6f7ca0df8146d408f9ed14f8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aec1ab15a3a3c1959bc137aaad674fa9e0854ca354b2226c352901f4d7d7c9cc6c8ef8d805b3b1ad680672eebca52a332de916a5e10d5f4d8b7b439bb677c7c0
|
7
|
+
data.tar.gz: 9af5d9ce6dda38757fb33aa33d86c337cd40751fc55bad37ad5c3f98cb04225209953843b7ec137e9295b8da2c2a40a640c7735f1d623c17851621b577b7a03e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,153 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v8.0.8](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v8.0.8) (2024-02-12)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v8.0.7...v8.0.8)
|
6
|
+
|
7
|
+
**Implemented enhancements:**
|
8
|
+
|
9
|
+
- fix: ensure a new lock isn't conflicting with itself [\#830](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/830) ([mhenrixon](https://github.com/mhenrixon))
|
10
|
+
|
11
|
+
**Fixed bugs:**
|
12
|
+
|
13
|
+
- until\_and\_while\_executing not entering perform method on initial run [\#824](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/824)
|
14
|
+
- fix\(digest\): write digest on middleware call [\#774](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/774) ([mhenrixon](https://github.com/mhenrixon))
|
15
|
+
|
16
|
+
**Closed issues:**
|
17
|
+
|
18
|
+
- incompatibility with sidekiq-failures [\#790](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/790)
|
19
|
+
- Jobs queued during existing job inherit lock digest [\#766](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/766)
|
20
|
+
|
21
|
+
## [v8.0.7](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v8.0.7) (2024-02-05)
|
22
|
+
|
23
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v8.0.6...v8.0.7)
|
24
|
+
|
25
|
+
**Implemented enhancements:**
|
26
|
+
|
27
|
+
- chore\(ci\): add test coverage from bropoplpush [\#828](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/828) ([mhenrixon](https://github.com/mhenrixon))
|
28
|
+
|
29
|
+
**Fixed bugs:**
|
30
|
+
|
31
|
+
- fix\(xss\): sanitize parameters [\#829](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/829) ([mhenrixon](https://github.com/mhenrixon))
|
32
|
+
|
33
|
+
**Closed issues:**
|
34
|
+
|
35
|
+
- No 'Changelog' link is being displayed on https://rubygems.org/gems/sidekiq-unique-jobs [\#825](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/825)
|
36
|
+
- Using rspec matcher and getting: `NameError: uninitialized constant SidekiqUniqueJobs::Lock::BaseLock::Validator` [\#741](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/741)
|
37
|
+
|
38
|
+
**Merged pull requests:**
|
39
|
+
|
40
|
+
- Fix Testing Instructions [\#827](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/827) ([jherdman](https://github.com/jherdman))
|
41
|
+
|
42
|
+
## [v8.0.6](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v8.0.6) (2024-01-24)
|
43
|
+
|
44
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v8.0.5...v8.0.6)
|
45
|
+
|
46
|
+
**Implemented enhancements:**
|
47
|
+
|
48
|
+
- Returning same job id [\#814](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/814)
|
49
|
+
- fix: various minor issues [\#826](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/826) ([mhenrixon](https://github.com/mhenrixon))
|
50
|
+
|
51
|
+
**Closed issues:**
|
52
|
+
|
53
|
+
- should respond to `has_valid_sidekiq_options?` [\#822](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/822)
|
54
|
+
- Reaper manager registration is subject to race conditions [\#801](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/801)
|
55
|
+
- `while_executing` with `on_conflict: :reschedule` Reschedule job after job execution [\#800](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/800)
|
56
|
+
- Large retry queue causes reaper to run too slow [\#759](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/759)
|
57
|
+
|
58
|
+
**Merged pull requests:**
|
59
|
+
|
60
|
+
- fix: skip unless reaper was registered [\#820](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/820) ([mhenrixon](https://github.com/mhenrixon))
|
61
|
+
|
62
|
+
## [v8.0.5](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v8.0.5) (2023-11-11)
|
63
|
+
|
64
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v8.0.4...v8.0.5)
|
65
|
+
|
66
|
+
**Merged pull requests:**
|
67
|
+
|
68
|
+
- Bump @babel/traverse from 7.22.8 to 7.23.3 in /myapp [\#819](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/819) ([dependabot[bot]](https://github.com/apps/dependabot))
|
69
|
+
- Bump postcss from 8.4.21 to 8.4.31 in /myapp [\#811](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/811) ([dependabot[bot]](https://github.com/apps/dependabot))
|
70
|
+
- fix: `while_executing` should not invoke conflict strategy when the job was successfully executed \[v8\] [\#810](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/810) ([cuzik](https://github.com/cuzik))
|
71
|
+
- Bump actions/checkout from 3 to 4 [\#808](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/808) ([dependabot[bot]](https://github.com/apps/dependabot))
|
72
|
+
- Bump semver from 6.3.0 to 6.3.1 in /myapp [\#798](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/798) ([dependabot[bot]](https://github.com/apps/dependabot))
|
73
|
+
- Because `replace` is a client strategy, it should only remove client locks aka queue locks. [\#778](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/778) ([bigzed](https://github.com/bigzed))
|
74
|
+
|
75
|
+
## [v8.0.4](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v8.0.4) (2023-11-11)
|
76
|
+
|
77
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.31...v8.0.4)
|
78
|
+
|
79
|
+
**Implemented enhancements:**
|
80
|
+
|
81
|
+
- fix: ignore reek for now [\#818](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/818) ([mhenrixon](https://github.com/mhenrixon))
|
82
|
+
- fix\(ci\): allow tests to run in docker [\#805](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/805) ([Earlopain](https://github.com/Earlopain))
|
83
|
+
- chore\(deps\): bump'n lint'n such [\#797](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/797) ([mhenrixon](https://github.com/mhenrixon))
|
84
|
+
|
85
|
+
**Fixed bugs:**
|
86
|
+
|
87
|
+
- Sidekiq 7: Unsupported command argument type: TrueClass [\#816](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/816)
|
88
|
+
- fix\(web\): don't show bogus lock digests [\#804](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/804) ([Earlopain](https://github.com/Earlopain))
|
89
|
+
|
90
|
+
**Closed issues:**
|
91
|
+
|
92
|
+
- register\_reaper\_process nx: true crash Sidekiq on startup [\#817](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/817)
|
93
|
+
|
94
|
+
**Merged pull requests:**
|
95
|
+
|
96
|
+
- fix: Sidekiq 7.2 throws TypeError: Unsupported command argument type: TrueClass when using byscore: true [\#815](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/815) ([Amnesthesia](https://github.com/Amnesthesia))
|
97
|
+
- Add sidekiq\_option for on-conflict-reschedule perform\_in time [\#813](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/813) ([mgmarlow](https://github.com/mgmarlow))
|
98
|
+
- Handle strategy fallbacks properly [\#809](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/809) ([matejrisek](https://github.com/matejrisek))
|
99
|
+
- Fix CI status badge [\#802](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/802) ([tagliala](https://github.com/tagliala))
|
100
|
+
|
101
|
+
## [v7.1.31](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.31) (2023-08-28)
|
102
|
+
|
103
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v7.1.30...v7.1.31)
|
104
|
+
|
105
|
+
**Closed issues:**
|
106
|
+
|
107
|
+
- Should client middleware also be added to the Sidekiq server config? [\#803](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/803)
|
108
|
+
- 8.0.1 Time on locks & changelog UI is incorrect/wrong [\#761](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/761)
|
109
|
+
- Job executed twice when reaper runs [\#738](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/738)
|
110
|
+
|
111
|
+
## [v7.1.30](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v7.1.30) (2023-07-17)
|
112
|
+
|
113
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v8.0.3...v7.1.30)
|
114
|
+
|
115
|
+
**Closed issues:**
|
116
|
+
|
117
|
+
- Release new gem version with "fix replace deprecated rpoplpush w/lmove" [\#795](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/795)
|
118
|
+
- Redis has deprecated the `rpoplpush`command [\#793](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/793)
|
119
|
+
- Deprecation Warning: Use of rpoplpush command in Redis [\#792](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/792)
|
120
|
+
- Logging::Middleware.context can include empty string as key when lock is not set in job hash [\#785](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/785)
|
121
|
+
|
122
|
+
## [v8.0.3](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v8.0.3) (2023-05-27)
|
123
|
+
|
124
|
+
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v8.0.2...v8.0.3)
|
125
|
+
|
126
|
+
**Implemented enhancements:**
|
127
|
+
|
128
|
+
- chore\(ci\): improve matrix [\#775](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/775) ([mhenrixon](https://github.com/mhenrixon))
|
129
|
+
- chore\(ci\): better ci job output [\#772](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/772) ([mhenrixon](https://github.com/mhenrixon))
|
130
|
+
|
131
|
+
**Fixed bugs:**
|
132
|
+
|
133
|
+
- Add unlocked reflect to locksmith unlock! [\#783](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/783) ([ttstarck](https://github.com/ttstarck))
|
134
|
+
- fix\(locksmith\): replace deprecated rpoplpush w/lmove [\#781](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/781) ([GabrielaGuedes](https://github.com/GabrielaGuedes))
|
135
|
+
- fix\(unlock\): ensure callback and unlock [\#771](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/771) ([mhenrixon](https://github.com/mhenrixon))
|
136
|
+
|
137
|
+
**Closed issues:**
|
138
|
+
|
139
|
+
- `unlocked` reflection is never called [\#782](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/782)
|
140
|
+
- Migrate away from deprecated Redis commands [\#780](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/780)
|
141
|
+
- `while_executing` with `on_conflict: :reschedule` reschedules job when unlock fails [\#770](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/770)
|
142
|
+
- Redis server v6.0 compatibility [\#769](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/769)
|
143
|
+
- Locks not removed after worker finishes [\#758](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/758)
|
144
|
+
|
145
|
+
**Merged pull requests:**
|
146
|
+
|
147
|
+
- Add lock to item when lock\_type is pulled from Job class sidekiq options [\#786](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/786) ([ttstarck](https://github.com/ttstarck))
|
148
|
+
- Fix rubocop failure by expecting array to be empty [\#784](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/784) ([GabrielaGuedes](https://github.com/GabrielaGuedes))
|
149
|
+
- fix\(doc\): improve information on unlock\_failed [\#776](https://github.com/mhenrixon/sidekiq-unique-jobs/pull/776) ([mhenrixon](https://github.com/mhenrixon))
|
150
|
+
|
3
151
|
## [v8.0.2](https://github.com/mhenrixon/sidekiq-unique-jobs/tree/v8.0.2) (2023-03-13)
|
4
152
|
|
5
153
|
[Full Changelog](https://github.com/mhenrixon/sidekiq-unique-jobs/compare/v8.0.1...v8.0.2)
|
@@ -266,7 +414,6 @@
|
|
266
414
|
|
267
415
|
- Job finished, but lock is not cleared [\#677](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/677)
|
268
416
|
- sidekiq\_options lock conflicts with sidekiq-lock gem lock option [\#669](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/669)
|
269
|
-
- Slow evalsha causing timeouts [\#668](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/668)
|
270
417
|
- Inconsistent documentation for config validation [\#647](https://github.com/mhenrixon/sidekiq-unique-jobs/issues/647)
|
271
418
|
|
272
419
|
**Merged pull requests:**
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SidekiqUniqueJobs
|
2
2
|
|
3
|
-
[![Join the chat at https://gitter.im/mhenrixon/sidekiq-unique-jobs](https://badges.gitter.im/mhenrixon/sidekiq-unique-jobs.svg)](https://gitter.im/mhenrixon/sidekiq-unique-jobs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ![Build Status](https://github.com/mhenrixon/sidekiq-unique-jobs/actions/workflows/rspec.yml/badge.svg?branch=
|
3
|
+
[![Join the chat at https://gitter.im/mhenrixon/sidekiq-unique-jobs](https://badges.gitter.im/mhenrixon/sidekiq-unique-jobs.svg)](https://gitter.im/mhenrixon/sidekiq-unique-jobs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ![Build Status](https://github.com/mhenrixon/sidekiq-unique-jobs/actions/workflows/rspec.yml/badge.svg?branch=main) [![Code Climate](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs.svg)](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs) [![Test Coverage](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs/badges/coverage.svg)](https://codeclimate.com/github/mhenrixon/sidekiq-unique-jobs/coverage)
|
4
4
|
|
5
5
|
## Support Me
|
6
6
|
|
@@ -582,8 +582,6 @@ end
|
|
582
582
|
#spec/workers/bad_worker_spec.rb
|
583
583
|
|
584
584
|
require "sidekiq_unique_jobs/testing"
|
585
|
-
#OR
|
586
|
-
require "sidekiq_unique_jobs/rspec/matchers"
|
587
585
|
|
588
586
|
RSpec.describe BadWorker do
|
589
587
|
specify { expect(described_class).to have_valid_sidekiq_options }
|
@@ -816,7 +814,7 @@ In my benchmarks deleting 1000 orphaned locks with lua performs around 65% faste
|
|
816
814
|
|
817
815
|
On the other hand if I increase it to 10 000 orphaned locks per cleanup (`reaper_count: 10_0000`) then redis starts throwing:
|
818
816
|
|
819
|
-
> BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. (
|
817
|
+
> BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. (RedisClient::CommandError)
|
820
818
|
|
821
819
|
If you want to disable the reaper set it to `:none`, `nil` or `false`. Actually, any value that isn't `:ruby` or `:lua` will disable the reaping.
|
822
820
|
|
@@ -59,7 +59,7 @@ module SidekiqUniqueJobs
|
|
59
59
|
# NOTE: When debugging, check the last item in the returned array.
|
60
60
|
[
|
61
61
|
total_size.to_i,
|
62
|
-
result[0].to_i,
|
62
|
+
result[0].to_i, # next_cursor
|
63
63
|
result[1].map { |entry| load_json(entry) }.select { |entry| entry.is_a?(Hash) },
|
64
64
|
]
|
65
65
|
end
|
@@ -67,10 +67,10 @@ module SidekiqUniqueJobs
|
|
67
67
|
# @return [Hash<Symbol, SidekiqUniqueJobs::Lock::BaseLock] all available default locks
|
68
68
|
LOCKS =
|
69
69
|
LOCKS_WHEN_BUSY.dup
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
.merge(LOCKS_WHILE_ENQUEUED.dup)
|
71
|
+
.merge(LOCKS_WITHOUT_UNLOCK.dup)
|
72
|
+
.merge(LOCKS_FROM_PUSH_TO_PROCESSED.dup)
|
73
|
+
.freeze
|
74
74
|
|
75
75
|
#
|
76
76
|
# @return [Hash<Symbol, SidekiqUniqueJobs::OnConflict::Strategy] all available default strategies
|
@@ -7,6 +7,16 @@ module SidekiqUniqueJobs
|
|
7
7
|
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
8
8
|
#
|
9
9
|
class Digests < Redis::SortedSet
|
10
|
+
#
|
11
|
+
# @return [Integer] the number of matches to return by default
|
12
|
+
DEFAULT_COUNT = 1_000
|
13
|
+
#
|
14
|
+
# @return [String] the default pattern to use for matching
|
15
|
+
SCAN_PATTERN = "*"
|
16
|
+
#
|
17
|
+
# @return [Array(String, String, String, String)] The empty runtime or queuetime keys.
|
18
|
+
EMPTY_KEYS_SEGMENT = ["", "", "", ""].freeze
|
19
|
+
|
10
20
|
def initialize(digests_key = DIGESTS)
|
11
21
|
super(digests_key)
|
12
22
|
end
|
@@ -41,19 +51,14 @@ module SidekiqUniqueJobs
|
|
41
51
|
# Also deletes the :AVAILABLE, :EXPIRED etc keys
|
42
52
|
#
|
43
53
|
# @param [String] digest a unique digest to delete
|
44
|
-
|
54
|
+
# @param queuetime [Boolean] Whether to delete queue locks.
|
55
|
+
# @param runtime [Boolean] Whether to delete run locks.
|
56
|
+
def delete_by_digest(digest, queuetime: true, runtime: true)
|
45
57
|
result, elapsed = timed do
|
46
|
-
call_script(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
"#{digest}:LOCKED",
|
51
|
-
"#{digest}:RUN",
|
52
|
-
"#{digest}:RUN:QUEUED",
|
53
|
-
"#{digest}:RUN:PRIMED",
|
54
|
-
"#{digest}:RUN:LOCKED",
|
55
|
-
key,
|
56
|
-
])
|
58
|
+
call_script(
|
59
|
+
:delete_by_digest,
|
60
|
+
queuetime_keys(queuetime ? digest : nil) + runtime_keys(runtime ? digest : nil) + [key],
|
61
|
+
)
|
57
62
|
end
|
58
63
|
|
59
64
|
log_info("#{__method__}(#{digest}) completed in #{elapsed}ms")
|
@@ -93,9 +98,37 @@ module SidekiqUniqueJobs
|
|
93
98
|
[
|
94
99
|
total_size.to_i,
|
95
100
|
digests[0].to_i, # next_cursor
|
96
|
-
digests[1].map { |digest, score| Lock.new(digest, time: score) }, # entries
|
101
|
+
digests[1].each_slice(2).map { |digest, score| Lock.new(digest, time: score) }, # entries
|
97
102
|
]
|
98
103
|
end
|
99
104
|
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
# @param digest [String, nil] The digest to form runtime keys from.
|
109
|
+
# @return [Array(String, String, String, String)] The list of runtime keys or empty strings if +digest+ was +nil+.
|
110
|
+
def runtime_keys(digest)
|
111
|
+
return EMPTY_KEYS_SEGMENT unless digest
|
112
|
+
|
113
|
+
[
|
114
|
+
"#{digest}:RUN",
|
115
|
+
"#{digest}:RUN:QUEUED",
|
116
|
+
"#{digest}:RUN:PRIMED",
|
117
|
+
"#{digest}:RUN:LOCKED",
|
118
|
+
]
|
119
|
+
end
|
120
|
+
|
121
|
+
# @param digest [String, nil] The digest to form queuetime keys from.
|
122
|
+
# @return [Array(String, String, String, String)] The list of queuetime keys or empty strings if +digest+ was +nil+.
|
123
|
+
def queuetime_keys(digest)
|
124
|
+
return EMPTY_KEYS_SEGMENT unless digest
|
125
|
+
|
126
|
+
[
|
127
|
+
digest,
|
128
|
+
"#{digest}:QUEUED",
|
129
|
+
"#{digest}:PRIMED",
|
130
|
+
"#{digest}:LOCKED",
|
131
|
+
]
|
132
|
+
end
|
100
133
|
end
|
101
134
|
end
|
@@ -41,19 +41,19 @@ module SidekiqUniqueJobs
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def add_lock_timeout(item)
|
44
|
-
item[LOCK_TIMEOUT]
|
44
|
+
item[LOCK_TIMEOUT] = SidekiqUniqueJobs::LockTimeout.calculate(item)
|
45
45
|
end
|
46
46
|
|
47
47
|
def add_lock_args(item)
|
48
|
-
item[LOCK_ARGS]
|
48
|
+
item[LOCK_ARGS] = SidekiqUniqueJobs::LockArgs.call(item)
|
49
49
|
end
|
50
50
|
|
51
51
|
def add_lock_digest(item)
|
52
|
-
item[LOCK_DIGEST]
|
52
|
+
item[LOCK_DIGEST] = SidekiqUniqueJobs::LockDigest.call(item)
|
53
53
|
end
|
54
54
|
|
55
55
|
def add_lock_prefix(item)
|
56
|
-
item[LOCK_PREFIX]
|
56
|
+
item[LOCK_PREFIX] = SidekiqUniqueJobs.config.lock_prefix
|
57
57
|
end
|
58
58
|
|
59
59
|
def add_lock_type(item)
|
@@ -109,7 +109,7 @@ module SidekiqUniqueJobs
|
|
109
109
|
#
|
110
110
|
# Call whatever strategry that has been configured
|
111
111
|
#
|
112
|
-
# @param [Symbol] origin
|
112
|
+
# @param [Symbol] origin the origin `:client` or `:server`
|
113
113
|
#
|
114
114
|
# @return [void] the return value is irrelevant
|
115
115
|
#
|
@@ -11,6 +11,8 @@ module SidekiqUniqueJobs
|
|
11
11
|
#
|
12
12
|
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
13
13
|
class WhileExecuting < BaseLock
|
14
|
+
#
|
15
|
+
# @return [String] returns :RUN
|
14
16
|
RUN_SUFFIX = ":RUN"
|
15
17
|
|
16
18
|
include SidekiqUniqueJobs::OptionsWithFallback
|
@@ -42,6 +44,7 @@ module SidekiqUniqueJobs
|
|
42
44
|
with_logging_context do
|
43
45
|
executed = locksmith.execute do
|
44
46
|
yield
|
47
|
+
item[JID]
|
45
48
|
ensure
|
46
49
|
unlock_and_callback
|
47
50
|
end
|
@@ -33,9 +33,9 @@ module SidekiqUniqueJobs
|
|
33
33
|
#
|
34
34
|
# @return [Lock] a newly lock that has been locked
|
35
35
|
#
|
36
|
-
def self.create(digest, job_id, lock_info
|
37
|
-
lock = new(digest, time:
|
38
|
-
lock.lock(job_id, lock_info)
|
36
|
+
def self.create(digest, job_id, lock_info: {}, time: Timing.now_f, score: nil)
|
37
|
+
lock = new(digest, time: time)
|
38
|
+
lock.lock(job_id, lock_info, score)
|
39
39
|
lock
|
40
40
|
end
|
41
41
|
|
@@ -47,7 +47,7 @@ module SidekiqUniqueJobs
|
|
47
47
|
#
|
48
48
|
def initialize(key, time: nil)
|
49
49
|
@key = get_key(key)
|
50
|
-
time = time.is_a?(Float)
|
50
|
+
time = time.to_f unless time.is_a?(Float)
|
51
51
|
return unless time.nonzero?
|
52
52
|
|
53
53
|
@created_at = time
|
@@ -63,15 +63,16 @@ module SidekiqUniqueJobs
|
|
63
63
|
#
|
64
64
|
# @return [void]
|
65
65
|
#
|
66
|
-
def lock(job_id, lock_info = {})
|
66
|
+
def lock(job_id, lock_info = {}, score = nil)
|
67
|
+
score ||= now_f
|
67
68
|
redis do |conn|
|
68
69
|
conn.multi do |pipeline|
|
69
70
|
pipeline.set(key.digest, job_id)
|
70
71
|
pipeline.hset(key.locked, job_id, now_f)
|
71
72
|
info.set(lock_info, pipeline)
|
72
|
-
add_digest_to_set(pipeline, lock_info)
|
73
|
-
pipeline.zadd(key.changelog,
|
74
|
-
pipeline.zadd(key.changelog,
|
73
|
+
add_digest_to_set(pipeline, lock_info, score)
|
74
|
+
pipeline.zadd(key.changelog, score, changelog_json(job_id, "queue.lua", "Queued"))
|
75
|
+
pipeline.zadd(key.changelog, score, changelog_json(job_id, "lock.lua", "Locked"))
|
75
76
|
end
|
76
77
|
end
|
77
78
|
end
|
@@ -333,12 +334,14 @@ module SidekiqUniqueJobs
|
|
333
334
|
#
|
334
335
|
# @return [nil]
|
335
336
|
#
|
336
|
-
def add_digest_to_set(pipeline, lock_info)
|
337
|
+
def add_digest_to_set(pipeline, lock_info, score = nil)
|
338
|
+
score ||= now_f
|
337
339
|
digest_string = key.digest
|
340
|
+
|
338
341
|
if lock_info["lock"] == :until_expired
|
339
|
-
pipeline.zadd(key.expiring_digests,
|
342
|
+
pipeline.zadd(key.expiring_digests, score + lock_info["ttl"], digest_string)
|
340
343
|
else
|
341
|
-
pipeline.zadd(key.digests,
|
344
|
+
pipeline.zadd(key.digests, score, digest_string)
|
342
345
|
end
|
343
346
|
end
|
344
347
|
end
|
@@ -113,14 +113,20 @@ module SidekiqUniqueJobs
|
|
113
113
|
|
114
114
|
# the strategy to use as conflict resolution from sidekiq client
|
115
115
|
def on_client_conflict
|
116
|
-
@on_client_conflict ||=
|
117
|
-
|
116
|
+
@on_client_conflict ||= if on_conflict.is_a?(Hash)
|
117
|
+
on_conflict["client"] || on_conflict[:client]
|
118
|
+
else
|
119
|
+
on_conflict
|
120
|
+
end
|
118
121
|
end
|
119
122
|
|
120
123
|
# the strategy to use as conflict resolution from sidekiq server
|
121
124
|
def on_server_conflict
|
122
|
-
@on_server_conflict ||=
|
123
|
-
|
125
|
+
@on_server_conflict ||= if on_conflict.is_a?(Hash)
|
126
|
+
on_conflict["server"] || on_conflict[:server]
|
127
|
+
else
|
128
|
+
on_conflict
|
129
|
+
end
|
124
130
|
end
|
125
131
|
end
|
126
132
|
end
|
@@ -188,7 +188,7 @@ module SidekiqUniqueJobs
|
|
188
188
|
#
|
189
189
|
# @param [Sidekiq::RedisConnection, ConnectionPool] conn the redis connection
|
190
190
|
# @param [Method] primed_method reference to the method to use for getting a primed token
|
191
|
-
# @param [nil, Integer, Float] time to wait before timeout
|
191
|
+
# @param [nil, Integer, Float] wait time to wait before timeout
|
192
192
|
#
|
193
193
|
# @yieldparam [string] job_id the sidekiq JID
|
194
194
|
# @yieldreturn [void] whatever the calling block returns
|
@@ -258,8 +258,8 @@ module SidekiqUniqueJobs
|
|
258
258
|
|
259
259
|
# NOTE: When debugging, change .value to .value!
|
260
260
|
primed_jid = Concurrent::Promises
|
261
|
-
|
262
|
-
|
261
|
+
.future(conn) { |red_con| pop_queued(red_con, timeout) }
|
262
|
+
.value
|
263
263
|
|
264
264
|
handle_primed(primed_jid, &block)
|
265
265
|
end
|
@@ -75,21 +75,28 @@ if lock_type ~= "until_expired" then
|
|
75
75
|
redis.call("HDEL", locked, job_id)
|
76
76
|
end
|
77
77
|
|
78
|
+
if redis.call("LLEN", primed) == 0 then
|
79
|
+
log_debug("UNLINK", primed)
|
80
|
+
redis.call("UNLINK", primed)
|
81
|
+
end
|
82
|
+
|
78
83
|
local locked_count = redis.call("HLEN", locked)
|
79
84
|
|
80
|
-
if locked_count
|
85
|
+
if locked_count < 1 then
|
81
86
|
log_debug("UNLINK", locked)
|
82
87
|
redis.call("UNLINK", locked)
|
83
88
|
end
|
84
89
|
|
85
|
-
if
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
if limit then
|
91
|
+
if limit <= 1 and locked_count <= 1 then
|
92
|
+
log_debug("ZREM", digests, digest)
|
93
|
+
redis.call("ZREM", digests, digest)
|
94
|
+
end
|
95
|
+
else
|
96
|
+
if locked_count <= 1 then
|
97
|
+
log_debug("ZREM", digests, digest)
|
98
|
+
redis.call("ZREM", digests, digest)
|
99
|
+
end
|
93
100
|
end
|
94
101
|
|
95
102
|
log_debug("LPUSH", queued, "1")
|
@@ -6,7 +6,7 @@ module SidekiqUniqueJobs
|
|
6
6
|
#
|
7
7
|
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
8
8
|
class Client
|
9
|
-
include Sidekiq::ClientMiddleware
|
9
|
+
include Sidekiq::ClientMiddleware
|
10
10
|
|
11
11
|
# prepend "SidekiqUniqueJobs::Middleware"
|
12
12
|
# @!parse prepends SidekiqUniqueJobs::Middleware
|
@@ -6,7 +6,7 @@ module SidekiqUniqueJobs
|
|
6
6
|
#
|
7
7
|
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
8
8
|
class Server
|
9
|
-
include Sidekiq::ServerMiddleware
|
9
|
+
include Sidekiq::ServerMiddleware
|
10
10
|
|
11
11
|
# prepend "SidekiqUniqueJobs::Middleware"
|
12
12
|
# @!parse prepends SidekiqUniqueJobs::Middleware
|
@@ -19,15 +19,15 @@ module SidekiqUniqueJobs
|
|
19
19
|
# This method runs before (prepended) the actual middleware implementation.
|
20
20
|
# This is done to reduce duplication
|
21
21
|
#
|
22
|
-
# @param [Sidekiq::
|
22
|
+
# @param [Sidekiq::Job] worker_class
|
23
23
|
# @param [Hash] item a sidekiq job hash
|
24
24
|
# @param [String] queue name of the queue
|
25
25
|
# @param [ConnectionPool] redis_pool only used for compatility reasons
|
26
26
|
#
|
27
|
-
# @return [yield<super>]
|
27
|
+
# @return [yield<super>] call the rest of the middleware stack
|
28
28
|
#
|
29
|
-
# @yieldparam [
|
30
|
-
# @yieldreturn [
|
29
|
+
# @yieldparam [void] if uniquejobs is disable
|
30
|
+
# @yieldreturn [void] delegate back to other sidekiq middleware
|
31
31
|
def call(worker_class, item, queue, redis_pool = nil)
|
32
32
|
@item = item
|
33
33
|
@queue = queue
|
@@ -35,7 +35,7 @@ module SidekiqUniqueJobs
|
|
35
35
|
self.job_class = worker_class
|
36
36
|
return yield if unique_disabled?
|
37
37
|
|
38
|
-
SidekiqUniqueJobs::Job.prepare(item)
|
38
|
+
SidekiqUniqueJobs::Job.prepare(item)
|
39
39
|
|
40
40
|
with_logging_context do
|
41
41
|
super
|
@@ -21,7 +21,7 @@ module SidekiqUniqueJobs
|
|
21
21
|
# This will mess up sidekiq stats because a new job is created
|
22
22
|
def call
|
23
23
|
if sidekiq_job_class?
|
24
|
-
if job_class.set(queue: item["queue"].to_sym).perform_in(
|
24
|
+
if job_class.set(queue: item["queue"].to_sym).perform_in(schedule_in, *item[ARGS])
|
25
25
|
reflect(:rescheduled, item)
|
26
26
|
else
|
27
27
|
reflect(:reschedule_failed, item)
|
@@ -30,6 +30,10 @@ module SidekiqUniqueJobs
|
|
30
30
|
reflect(:unknown_sidekiq_worker, item)
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
def schedule_in
|
35
|
+
job_class.get_sidekiq_options["schedule_in"] || 5
|
36
|
+
end
|
33
37
|
end
|
34
38
|
end
|
35
39
|
end
|
@@ -39,12 +39,13 @@ module SidekiqUniqueJobs
|
|
39
39
|
self.task = test_task || default_task
|
40
40
|
|
41
41
|
with_logging_context do
|
42
|
-
register_reaper_process
|
43
|
-
|
42
|
+
if register_reaper_process
|
43
|
+
log_info("Starting Reaper")
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
task.add_observer(Observer.new)
|
46
|
+
task.execute
|
47
|
+
task
|
48
|
+
end
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
@@ -192,7 +193,7 @@ module SidekiqUniqueJobs
|
|
192
193
|
# @return [void]
|
193
194
|
#
|
194
195
|
def register_reaper_process
|
195
|
-
redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, nx
|
196
|
+
redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, "nx", "ex", drift_reaper_interval) }
|
196
197
|
end
|
197
198
|
|
198
199
|
#
|
@@ -202,7 +203,7 @@ module SidekiqUniqueJobs
|
|
202
203
|
# @return [void]
|
203
204
|
#
|
204
205
|
def refresh_reaper_mutex
|
205
|
-
redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, ex
|
206
|
+
redis { |conn| conn.set(UNIQUE_REAPER, current_timestamp, "ex", drift_reaper_interval) }
|
206
207
|
end
|
207
208
|
|
208
209
|
#
|