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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a407572b8a6542f0303eecdedf53a58af589bef195ca15400880d417e510feb7
4
- data.tar.gz: 65bd030916284341db0f3a0bde6c72a223664c05ed1b92a7637a8a7c436851d5
3
+ metadata.gz: 47756fe648b47e5e2be0c37e2d57d8ddc13beea68eff40cba671002813965b25
4
+ data.tar.gz: 8d9aeec1c29e60b4f98eb7f5ce77be820238f84e2e103175fc039fd7fac5aeca
5
5
  SHA512:
6
- metadata.gz: 0e7adcf507b7e9f53ec3ed53a841ea460a24bd3851e6e46697c5bb2776f3a6c3aea0f54fbcd8669e57c36e6d6470a5edbacd9495ca315505690e6583d40ad2b5
7
- data.tar.gz: 57074e6a7161fcaf5706598dd1d13fcaf878f70d3345344e1cc5b3d120928079a734608df3f4f5355545cf937864f31bc4b031d04d54ab191aa19601e93fd2ea
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.0...HEAD)
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 clanup 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:
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(**lock_options.merge(lock_key: lock_key, job: self))
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
- arguments: lock_key_arguments
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
 
@@ -28,6 +28,14 @@ module ActiveJob
28
28
  ].join(':')
29
29
  end
30
30
 
31
+ # used only by :until_and_while_executing strategy
32
+ def runtime_lock_key
33
+ [
34
+ lock_key,
35
+ 'runtime'
36
+ ].join(':')
37
+ end
38
+
31
39
  def wildcard_key
32
40
  [
33
41
  lock_prefix,
@@ -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 Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('5.1')
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(lock_key:, lock_ttl: nil, on_conflict: nil, job: nil)
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(runtime_lock_ttl: nil, on_runtime_conflict: nil, **params)
15
- super(**params)
16
- @runtime_lock_ttl = runtime_lock_ttl.present? ? runtime_lock_ttl.to_i * 1000 : lock_ttl
17
- @on_runtime_conflict = on_runtime_conflict || on_conflict
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveJob
4
4
  module Uniqueness
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.3'
6
6
  end
7
7
  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.0
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: 2021-05-09 00:00:00.000000000 Z
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.2.15
161
+ rubygems_version: 3.1.6
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: Ensure uniqueness of your ActiveJob jobs