activejob-lockable 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/activejob/lockable/lockable.rb +20 -21
- data/lib/activejob/lockable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7030403a0857ccb1c8c520af5f8aa65dae5c62436d3b2ee6aba9e98b5150200
|
4
|
+
data.tar.gz: a2e9f0462fadb5601d318b702b9fb242cbe6f5ced1eb93a2004ed9d8e98ffd91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2020-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|