activejob-uniqueness 0.2.1 → 0.2.4

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: 56ef0f3d36e4bbad62cd210b5e0d57798854e01b3ca539bcdcec73901d6b3565
4
- data.tar.gz: 1c76f1e1d906d7caacc3948cb55aa6ac89842ff8ef00e2f54f2200fbc3869475
3
+ metadata.gz: be824ecac1e864d000509ee27bb2a19a41bf1c0dbbb92fe49517a5a7fe1c86ff
4
+ data.tar.gz: a0d50fcdea9e48a952f6574604f3286b4de994b780299b99434c04f8ca0d16b1
5
5
  SHA512:
6
- metadata.gz: 20c7aa349360a2f0dae02ac661b572f8c7b524071407e315d868998cd616f36631c42cce6cecbae4f2668cda1e0543e1e5c7f9b4e0f27a9a23bfa5c4a72aa637
7
- data.tar.gz: 58dee76d6d5ef595920dbee7fdea277f8597ff4e12a11ad2373e5667eea4bb7cb33363ebfbfe5445a693ec875745bf46187668c4b20a5e96dc6c988b4c4b1b1b
6
+ metadata.gz: e890759b54e003eea294906ed47055f71065ad8763538d1ada3c4985ebbed3492f4ce8ee91f6d732222e1b206d1caff023d8d73f019072642c0bd8873da870cf
7
+ data.tar.gz: 878c1af167966d9093ffacf90e919e78d8a5de57a92ae68f7475f4717b4e777af95ab413c27d77d86000fa328b6167d7d2e841c3ff9eee7379cc6e573d3b91ff
data/CHANGELOG.md CHANGED
@@ -3,7 +3,28 @@ 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.4...HEAD)
7
+
8
+
9
+ ## [0.2.4](https://github.com/veeqo/activejob-uniqueness/compare/v0.2.3...v0.2.4) - 2022-06-22
10
+
11
+ ### Added
12
+ - [#43](https://github.com/veeqo/activejob-uniqueness/pull/43) Run rubocop on Github Actions
13
+ - [#44](https://github.com/veeqo/activejob-uniqueness/pull/44) Add ActiveJob::Uniqueness.test_mode! method to reset lock manager by [@akostadinov](https://github.com/akostadinov)
14
+
15
+ ### Changed
16
+ - [#42](https://github.com/veeqo/activejob-uniqueness/pull/42) Actualize rubies and gems for tests
17
+
18
+ ## [0.2.3](https://github.com/veeqo/activejob-uniqueness/compare/v0.2.2...v0.2.3) - 2022-02-28
19
+
20
+ ### Added
21
+ - [#36](https://github.com/veeqo/activejob-uniqueness/pull/36) Support ActiveJob/Rails 7.0
22
+ - [#37](https://github.com/veeqo/activejob-uniqueness/pull/37) Add Ruby 3.1 to CI by [@petergoldstein](https://github.com/petergoldstein)
23
+
24
+ ## [0.2.2](https://github.com/veeqo/activejob-uniqueness/compare/v0.2.1...v0.2.2) - 2021-10-22
25
+
26
+ ### Added
27
+ - [#32](https://github.com/veeqo/activejob-uniqueness/pull/32) Add ability to set a custom runtime lock key for `:until_and_while_executing` strategy
7
28
 
8
29
  ## [0.2.1](https://github.com/veeqo/activejob-uniqueness/compare/v0.2.0...v0.2.1) - 2021-08-24
9
30
 
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,11 +28,19 @@ 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,
34
42
  normalized_job_class_name,
35
- arguments.any? ? arguments_key_part + '*' : '*'
43
+ arguments.any? ? "#{arguments_key_part}*" : '*'
36
44
  ].compact.join(':')
37
45
  end
38
46
 
@@ -9,7 +9,7 @@ module ActiveJob
9
9
  # Unlocks a resource by resource only.
10
10
  def delete_lock(resource)
11
11
  @servers.each do |server|
12
- server.instance_variable_get(:'@redis').with do |conn|
12
+ server.instance_variable_get(:@redis).with do |conn|
13
13
  conn.del resource
14
14
  end
15
15
  end
@@ -20,7 +20,7 @@ module ActiveJob
20
20
  # Unlocks multiple resources by key wildcard.
21
21
  def delete_locks(wildcard)
22
22
  @servers.each do |server|
23
- server.instance_variable_get(:'@redis').with do |conn|
23
+ server.instance_variable_get(:@redis).with do |conn|
24
24
  conn.scan_each(match: wildcard).each { |key| conn.del key }
25
25
  end
26
26
  end
@@ -3,7 +3,7 @@
3
3
  require 'active_support/log_subscriber'
4
4
 
5
5
  module ActiveJob
6
- class LogSubscriber < ActiveSupport::LogSubscriber #:nodoc:
6
+ class LogSubscriber < ActiveSupport::LogSubscriber # :nodoc:
7
7
  def lock(event)
8
8
  job = event.payload[:job]
9
9
  resource = event.payload[:resource]
@@ -66,8 +66,7 @@ module ActiveJob
66
66
 
67
67
  def args_info(job)
68
68
  if job.arguments.any? && log_arguments?(job)
69
- ' with arguments: ' +
70
- job.arguments.map { |arg| format(arg).inspect }.join(', ')
69
+ " with arguments: #{job.arguments.map { |arg| format(arg).inspect }.join(', ')}"
71
70
  else
72
71
  ''
73
72
  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.1'
5
+ VERSION = '0.2.4'
6
6
  end
7
7
  end
@@ -38,6 +38,10 @@ module ActiveJob
38
38
  def test_mode!
39
39
  @lock_manager = ActiveJob::Uniqueness::TestLockManager.new
40
40
  end
41
+
42
+ def reset_manager!
43
+ @lock_manager = nil
44
+ end
41
45
  end
42
46
  end
43
47
  end
@@ -15,7 +15,7 @@ ActiveJob::Uniqueness.configure do |config|
15
15
  # Allowed values are
16
16
  # :raise - raises ActiveJob::Uniqueness::JobNotUnique
17
17
  # :log - instruments ActiveSupport::Notifications and logs event to the ActiveJob::Logger
18
- # proc - custom Proc. For example, ->(job) { job.logger.info('Oops') }
18
+ # proc - custom Proc. For example, ->(job) { job.logger.info("Job already in queue: #{job.class.name} #{job.arguments.inspect} (#{job.job_id})") }
19
19
  #
20
20
  # config.on_conflict = :raise
21
21
 
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.1
4
+ version: 0.2.4
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-08-24 00:00:00.000000000 Z
11
+ date: 2022-06-22 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
@@ -106,6 +106,34 @@ dependencies:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
108
  version: '3.0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: rubocop
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '1.28'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '1.28'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rubocop-rspec
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '2.10'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '2.10'
109
137
  description: Ensure uniqueness of your ActiveJob jobs
110
138
  email:
111
139
  - rustam@sharshenov.com
@@ -143,6 +171,7 @@ metadata:
143
171
  homepage_uri: https://github.com/veeqo/activejob-uniqueness
144
172
  source_code_uri: https://github.com/veeqo/activejob-uniqueness
145
173
  changelog_uri: https://github.com/veeqo/activejob-uniqueness/blob/main/CHANGELOG.md
174
+ rubygems_mfa_required: 'true'
146
175
  post_install_message:
147
176
  rdoc_options: []
148
177
  require_paths:
@@ -158,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
187
  - !ruby/object:Gem::Version
159
188
  version: '0'
160
189
  requirements: []
161
- rubygems_version: 3.0.9
190
+ rubygems_version: 3.1.6
162
191
  signing_key:
163
192
  specification_version: 4
164
193
  summary: Ensure uniqueness of your ActiveJob jobs