activejob-lockable 0.1.4 → 0.1.5
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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 664f6c1cc3b4fcaa153c34c1a3dd734c66a45dbbcfa751d79c23a24f2e5bcc58
|
4
|
+
data.tar.gz: e1a97f5959d30c1357d77a2fe628e63a367215c08ee1c6e3bf57b33eb1faf4cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45c4f6b76f35093fbf81926898794ccac7444b8aef051b16e7b6113956f65ef02a0fae3b3d1d8282758a226de4a6a712ddae4e3c426d5e6a488ffefb4e07955f
|
7
|
+
data.tar.gz: 5343ddb76f4e63fe321604d2f73df42d98d89d030922489878db6b6e6c9af5e30d7dc1f0e5a650679e05e46b2f453e0a8ad2cbb73bc95561472efc601ba4a077
|
data/lib/activejob/lockable.rb
CHANGED
@@ -30,8 +30,7 @@ module ActiveJob
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
# Returns the current Redis connection
|
34
|
-
# create a new one.
|
33
|
+
# Returns the current Redis connection, raising an error if it hasn't been created
|
35
34
|
def redis
|
36
35
|
return @redis if @redis
|
37
36
|
raise 'Redis is not configured'
|
@@ -17,7 +17,7 @@ module ActiveJob
|
|
17
17
|
def enqueue(options = {})
|
18
18
|
@options = options
|
19
19
|
if locked?
|
20
|
-
logger.info "
|
20
|
+
logger.info "Job is locked, expires in #{locked_ttl} second(s)"
|
21
21
|
send(on_locked_action) if on_locked_action && respond_to?(on_locked_action)
|
22
22
|
else
|
23
23
|
lock!
|
@@ -27,18 +27,25 @@ module ActiveJob
|
|
27
27
|
|
28
28
|
def lock!
|
29
29
|
return if lock_period.to_i <= 0
|
30
|
-
logger.info "
|
30
|
+
logger.info "Acquiring lock #{lock_extra_info}"
|
31
31
|
begin
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
39
46
|
def unlock!
|
40
47
|
return unless locked?
|
41
|
-
logger.info "
|
48
|
+
logger.info "Releasing lock #{lock_extra_info}"
|
42
49
|
ActiveJob::Lockable::RedisStore.del(lock_key)
|
43
50
|
end
|
44
51
|
|
@@ -58,7 +65,13 @@ module ActiveJob
|
|
58
65
|
private
|
59
66
|
|
60
67
|
def lock_period
|
61
|
-
options
|
68
|
+
return 0 unless options
|
69
|
+
|
70
|
+
options[:lock].to_i
|
71
|
+
end
|
72
|
+
|
73
|
+
def lock_extra_info
|
74
|
+
"[key #{lock_key}] [seconds #{lock_period.to_i}] [job_id #{self.job_id}] [class_name: #{self.class}]"
|
62
75
|
end
|
63
76
|
end
|
64
77
|
end
|
@@ -2,8 +2,8 @@ module ActiveJob
|
|
2
2
|
module Lockable
|
3
3
|
class RedisStore
|
4
4
|
class << self
|
5
|
-
def
|
6
|
-
ActiveJob::Lockable.redis.
|
5
|
+
def set(cache_key, cache_value, options = {})
|
6
|
+
ActiveJob::Lockable.redis.set(cache_key, cache_value, options)
|
7
7
|
end
|
8
8
|
|
9
9
|
def exists?(cache_key)
|
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.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmytro Zakharov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -148,8 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
|
-
|
152
|
-
rubygems_version: 2.6.13
|
151
|
+
rubygems_version: 3.0.3
|
153
152
|
signing_key:
|
154
153
|
specification_version: 4
|
155
154
|
summary: Prevents jobs from enqueuing with unique arguments for a certain period of
|