activejob-lockable 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 664f6c1cc3b4fcaa153c34c1a3dd734c66a45dbbcfa751d79c23a24f2e5bcc58
4
- data.tar.gz: e1a97f5959d30c1357d77a2fe628e63a367215c08ee1c6e3bf57b33eb1faf4cd
3
+ metadata.gz: e7030403a0857ccb1c8c520af5f8aa65dae5c62436d3b2ee6aba9e98b5150200
4
+ data.tar.gz: a2e9f0462fadb5601d318b702b9fb242cbe6f5ced1eb93a2004ed9d8e98ffd91
5
5
  SHA512:
6
- metadata.gz: 45c4f6b76f35093fbf81926898794ccac7444b8aef051b16e7b6113956f65ef02a0fae3b3d1d8282758a226de4a6a712ddae4e3c426d5e6a488ffefb4e07955f
7
- data.tar.gz: 5343ddb76f4e63fe321604d2f73df42d98d89d030922489878db6b6e6c9af5e30d7dc1f0e5a650679e05e46b2f453e0a8ad2cbb73bc95561472efc601ba4a077
6
+ metadata.gz: 182ce05c231b63b810e8d37d7ee9886f0552e461650d2f776bb56a7cd5f00cafe5ba0b1d969af72b4e18fedf783f9ef4042caf25f483437ae9db35c76ef8d48f
7
+ data.tar.gz: e6234683928e34b0c38172138ddaa95c9bc14510ad10b20b3d1c500a0c200824bc7653d3f53e09e9f826c2bd32cb8cf684e3323abec6d68fc88e585779a55601
@@ -16,31 +16,25 @@ module ActiveJob
16
16
 
17
17
  def enqueue(options = {})
18
18
  @options = options
19
- if locked?
20
- logger.info "Job is locked, expires in #{locked_ttl} second(s)"
21
- send(on_locked_action) if on_locked_action && respond_to?(on_locked_action)
22
- else
23
- lock!
24
- super(options)
25
- end
19
+ return trigger_on_locked_action unless lock!
20
+
21
+ super(options)
26
22
  end
27
23
 
28
24
  def lock!
29
- return if lock_period.to_i <= 0
25
+ return true if lock_period.to_i <= 0
30
26
  logger.info "Acquiring lock #{lock_extra_info}"
31
- begin
32
- # `:ex => Fixnum`: Set the specified expire time, in seconds.
33
- # `:nx => true`: Only set the key if it does not already exist.
34
- lock_acquired = ActiveJob::Lockable::RedisStore.set(
35
- lock_key,
36
- self.job_id,
37
- { ex: lock_period.to_i, nx: true }
38
- )
39
- raise "Could not acquire lock #{lock_extra_info}" unless lock_acquired
40
- rescue StandardError => e
41
- logger.info "EXCEPTION acquiring lock #{lock_extra_info}"
42
- raise
43
- end
27
+ # `:ex => Fixnum`: Set the specified expire time, in seconds.
28
+ # `:nx => true`: Only set the key if it does not already exist.
29
+ # Returns boolean, lock acquired or not
30
+ ActiveJob::Lockable::RedisStore.set(
31
+ lock_key,
32
+ self.job_id,
33
+ { ex: lock_period.to_i, nx: true }
34
+ )
35
+ rescue StandardError => e
36
+ logger.info "EXCEPTION acquiring lock #{lock_extra_info}"
37
+ raise
44
38
  end
45
39
 
46
40
  def unlock!
@@ -70,6 +64,11 @@ module ActiveJob
70
64
  options[:lock].to_i
71
65
  end
72
66
 
67
+ def trigger_on_locked_action
68
+ logger.info "Job is locked, expires in #{locked_ttl} second(s)"
69
+ public_send(on_locked_action) if on_locked_action && respond_to?(on_locked_action)
70
+ end
71
+
73
72
  def lock_extra_info
74
73
  "[key #{lock_key}] [seconds #{lock_period.to_i}] [job_id #{self.job_id}] [class_name: #{self.class}]"
75
74
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveJob
2
2
  module Lockable
3
- VERSION = '0.1.5'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob-lockable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmytro Zakharov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-13 00:00:00.000000000 Z
11
+ date: 2020-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob