activejob-uniqueness 0.2.1 → 0.2.2

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: 3892ccb031a8fe8b0bc47154ed236dda2a700b404dbcc9063b83479fbe264dc7
4
+ data.tar.gz: 73a8f4866017e2310bc0c966a49d2f25578921ad64b2e23a2c28931923b34b04
5
5
  SHA512:
6
- metadata.gz: 20c7aa349360a2f0dae02ac661b572f8c7b524071407e315d868998cd616f36631c42cce6cecbae4f2668cda1e0543e1e5c7f9b4e0f27a9a23bfa5c4a72aa637
7
- data.tar.gz: 58dee76d6d5ef595920dbee7fdea277f8597ff4e12a11ad2373e5667eea4bb7cb33363ebfbfe5445a693ec875745bf46187668c4b20a5e96dc6c988b4c4b1b1b
6
+ metadata.gz: a47bdbedbc98c95c24983ae4f46652f6c5f10584cfbe65312b4ee336a2d3fae21d03d6ea4c6b3fd09760cd5e9cfd3dde2fe02a89423e0918a6de0353a6f90c9b
7
+ data.tar.gz: ebfcf1e76b74662f5fb60008789b1858061c8685783a87317dff5818637064519894780f941c6a543687e02952747db2105e872efb95079e5b321a4f149e38bd
data/CHANGELOG.md CHANGED
@@ -3,7 +3,12 @@ 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.2...HEAD)
7
+
8
+ ## [0.2.2](https://github.com/veeqo/activejob-uniqueness/compare/v0.2.1...v0.2.2) - 2021-10-22
9
+
10
+ ### Added
11
+ - [#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
12
 
8
13
  ## [0.2.1](https://github.com/veeqo/activejob-uniqueness/compare/v0.2.0...v0.2.1) - 2021-08-24
9
14
 
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
 
@@ -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,
@@ -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.2'
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.1
4
+ version: 0.2.2
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: 2021-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob