activejob-uniqueness 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/README.md +5 -1
- data/lib/active_job/uniqueness/active_job_patch.rb +4 -4
- data/lib/active_job/uniqueness/lock_key.rb +8 -0
- data/lib/active_job/uniqueness/sidekiq_patch.rb +11 -2
- data/lib/active_job/uniqueness/strategies/base.rb +4 -4
- data/lib/active_job/uniqueness/strategies/until_and_while_executing.rb +9 -9
- data/lib/active_job/uniqueness/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47756fe648b47e5e2be0c37e2d57d8ddc13beea68eff40cba671002813965b25
|
4
|
+
data.tar.gz: 8d9aeec1c29e60b4f98eb7f5ce77be820238f84e2e103175fc039fd7fac5aeca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1903499d9c4f069ffc62df68353475404aac537e2eb65561e26f4d2fa527a75b0e9edb2c8e69a55a2c5ca3e13ee35891c7ab7292bd25647a8db89970d3f6696e
|
7
|
+
data.tar.gz: 9893c234256d0e91e988cdd7a1acf8db8a6e29bca23363d194f8c8f1b48d6d631347a5ad7c9299269eb0dccf35390900c71a28a824b55df4d9c4d6ba2c5e38e7
|
data/CHANGELOG.md
CHANGED
@@ -3,7 +3,23 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
5
5
|
|
6
|
-
## [Unreleased](https://github.com/veeqo/activejob-uniqueness/compare/v0.2.
|
6
|
+
## [Unreleased](https://github.com/veeqo/activejob-uniqueness/compare/v0.2.3...HEAD)
|
7
|
+
|
8
|
+
## [0.2.3](https://github.com/veeqo/activejob-uniqueness/compare/v0.2.2...v0.2.3) - 2022-02-28
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- [#36](https://github.com/veeqo/activejob-uniqueness/pull/36) Support ActiveJob/Rails 7.0
|
12
|
+
- [#37](https://github.com/veeqo/activejob-uniqueness/pull/37) Add Ruby 3.1 to CI by [@petergoldstein]
|
13
|
+
|
14
|
+
## [0.2.2](https://github.com/veeqo/activejob-uniqueness/compare/v0.2.1...v0.2.2) - 2021-10-22
|
15
|
+
|
16
|
+
### Added
|
17
|
+
- [#32](https://github.com/veeqo/activejob-uniqueness/pull/32) Add ability to set a custom runtime lock key for `:until_and_while_executing` strategy
|
18
|
+
|
19
|
+
## [0.2.1](https://github.com/veeqo/activejob-uniqueness/compare/v0.2.0...v0.2.1) - 2021-08-24
|
20
|
+
|
21
|
+
### Added
|
22
|
+
- [#30](https://github.com/veeqo/activejob-uniqueness/pull/30) Add Sidekiq::JobRecord support (reported by [@dwightwatson](https://github.com/dwightwatson))
|
7
23
|
|
8
24
|
## [0.2.0](https://github.com/veeqo/activejob-uniqueness/compare/v0.1.4...v0.2.0) - 2021-05-09
|
9
25
|
|
data/README.md
CHANGED
@@ -116,6 +116,10 @@ class MyJob < ActiveJob::Base
|
|
116
116
|
def lock_key
|
117
117
|
'qux' # completely custom lock key
|
118
118
|
end
|
119
|
+
|
120
|
+
def runtime_lock_key
|
121
|
+
'quux' # completely custom runtime lock key for :until_and_while_executing
|
122
|
+
end
|
119
123
|
end
|
120
124
|
```
|
121
125
|
|
@@ -177,7 +181,7 @@ rake
|
|
177
181
|
## Sidekiq API support
|
178
182
|
|
179
183
|
ActiveJob::Uniqueness supports Sidekiq API to unset job locks on queues cleanup (e.g. via Sidekiq Web UI). Starting Sidekiq 5.1 job death also triggers locks cleanup.
|
180
|
-
Take into account that **[big queues
|
184
|
+
Take into account that **[big queues cleanup becomes much slower](https://github.com/veeqo/activejob-uniqueness/issues/16)** because each job is being unlocked individually. In order to activate Sidekiq API patch require it explicitly in your Gemfile:
|
181
185
|
|
182
186
|
```ruby
|
183
187
|
gem 'activejob-uniqueness', require: 'active_job/uniqueness/sidekiq_patch'
|
@@ -55,7 +55,7 @@ module ActiveJob
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def lock_strategy
|
58
|
-
@lock_strategy ||= lock_strategy_class.new(
|
58
|
+
@lock_strategy ||= lock_strategy_class.new(job: self)
|
59
59
|
end
|
60
60
|
|
61
61
|
# Override in your job class if you want to customize arguments set for a digest.
|
@@ -64,11 +64,11 @@ module ActiveJob
|
|
64
64
|
end
|
65
65
|
|
66
66
|
# Override lock_key method in your job class if you want to build completely custom lock key.
|
67
|
-
delegate :lock_key, to: :lock_key_generator
|
67
|
+
delegate :lock_key, :runtime_lock_key, to: :lock_key_generator
|
68
68
|
|
69
69
|
def lock_key_generator
|
70
|
-
ActiveJob::Uniqueness::LockKey.new job_class_name: self.class.name,
|
71
|
-
|
70
|
+
@lock_key_generator ||= ActiveJob::Uniqueness::LockKey.new job_class_name: self.class.name,
|
71
|
+
arguments: lock_key_arguments
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -76,12 +76,21 @@ end
|
|
76
76
|
|
77
77
|
Sidekiq::SortedEntry.prepend ActiveJob::Uniqueness::SidekiqPatch::SortedEntry
|
78
78
|
Sidekiq::ScheduledSet.prepend ActiveJob::Uniqueness::SidekiqPatch::ScheduledSet
|
79
|
-
Sidekiq::Job.prepend ActiveJob::Uniqueness::SidekiqPatch::Job
|
80
79
|
Sidekiq::Queue.prepend ActiveJob::Uniqueness::SidekiqPatch::Queue
|
81
80
|
Sidekiq::JobSet.prepend ActiveJob::Uniqueness::SidekiqPatch::JobSet
|
82
81
|
|
82
|
+
sidekiq_version = Gem::Version.new(Sidekiq::VERSION)
|
83
|
+
|
84
|
+
# Sidekiq 6.2.2 renames Sidekiq::Job to Sidekiq::JobRecord
|
85
|
+
# https://github.com/mperham/sidekiq/issues/4955
|
86
|
+
if sidekiq_version >= Gem::Version.new('6.2.2')
|
87
|
+
Sidekiq::JobRecord.prepend ActiveJob::Uniqueness::SidekiqPatch::Job
|
88
|
+
else
|
89
|
+
Sidekiq::Job.prepend ActiveJob::Uniqueness::SidekiqPatch::Job
|
90
|
+
end
|
91
|
+
|
83
92
|
# Global death handlers are introduced in Sidekiq 5.1
|
84
93
|
# https://github.com/mperham/sidekiq/blob/e7acb124fbeb0bece0a7c3d657c39a9cc18d72c6/Changes.md#510
|
85
|
-
if
|
94
|
+
if sidekiq_version >= Gem::Version.new('5.1')
|
86
95
|
Sidekiq.death_handlers << ->(job, _ex) { ActiveJob::Uniqueness.unlock_sidekiq_job!(job) }
|
87
96
|
end
|
@@ -13,10 +13,10 @@ module ActiveJob
|
|
13
13
|
|
14
14
|
attr_reader :lock_key, :lock_ttl, :on_conflict, :job
|
15
15
|
|
16
|
-
def initialize(
|
17
|
-
@lock_key = lock_key
|
18
|
-
@lock_ttl = (lock_ttl || config.lock_ttl).to_i * 1000 # ms
|
19
|
-
@on_conflict = on_conflict || config.on_conflict
|
16
|
+
def initialize(job:)
|
17
|
+
@lock_key = job.lock_key
|
18
|
+
@lock_ttl = (job.lock_options[:lock_ttl] || config.lock_ttl).to_i * 1000 # ms
|
19
|
+
@on_conflict = job.lock_options[:on_conflict] || config.on_conflict
|
20
20
|
@job = job
|
21
21
|
end
|
22
22
|
|
@@ -9,12 +9,16 @@ module ActiveJob
|
|
9
9
|
class UntilAndWhileExecuting < Base
|
10
10
|
include LockingOnEnqueue
|
11
11
|
|
12
|
-
attr_reader :runtime_lock_ttl, :on_runtime_conflict
|
12
|
+
attr_reader :runtime_lock_key, :runtime_lock_ttl, :on_runtime_conflict
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
super
|
16
|
-
@
|
17
|
-
|
14
|
+
def initialize(job:)
|
15
|
+
super
|
16
|
+
@runtime_lock_key = job.runtime_lock_key
|
17
|
+
|
18
|
+
runtime_lock_ttl_option = job.lock_options[:runtime_lock_ttl]
|
19
|
+
@runtime_lock_ttl = runtime_lock_ttl_option.present? ? runtime_lock_ttl_option.to_i * 1000 : lock_ttl
|
20
|
+
|
21
|
+
@on_runtime_conflict = job.lock_options[:on_runtime_conflict] || on_conflict
|
18
22
|
end
|
19
23
|
|
20
24
|
def before_perform
|
@@ -33,10 +37,6 @@ module ActiveJob
|
|
33
37
|
ensure
|
34
38
|
unlock(resource: runtime_lock_key, event: :runtime_unlock) unless @job_aborted
|
35
39
|
end
|
36
|
-
|
37
|
-
def runtime_lock_key
|
38
|
-
[lock_key, 'runtime'].join(':')
|
39
|
-
end
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activejob-uniqueness
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Sharshenov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '7'
|
22
|
+
version: '7.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '7'
|
32
|
+
version: '7.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: redlock
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
|
-
rubygems_version: 3.
|
161
|
+
rubygems_version: 3.1.6
|
162
162
|
signing_key:
|
163
163
|
specification_version: 4
|
164
164
|
summary: Ensure uniqueness of your ActiveJob jobs
|