resque-better_unique 1.0.0 → 1.0.1
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 +4 -4
- data/lib/resque/plugins/better_unique.rb +14 -14
- data/lib/resque/plugins/better_unique/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e474de20786fbba4361851c129a2644738ca9bda
|
4
|
+
data.tar.gz: b887e51072a2ce8756536f1b7aed2fef67cbfc02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d04eeee9e17cf85359eb1b8865c635ae1f92b050a92d589161cb1f9daaef75d86cb3c7a6562ae9ec2ae7aa261d33dc0ea797899569cccf9fe09083d8236cb77e
|
7
|
+
data.tar.gz: 0cf12c119b33e5dff88e3036a5ba622e3cef1b446bda3ef57f3c57b64daa588ff00ade9f7e28ed8fcf18ebe7b9678ebc74148bfcc4280116d343f66693709cbd
|
@@ -12,7 +12,7 @@ module Resque
|
|
12
12
|
# passed the same arguments as `perform`, that is, your job's
|
13
13
|
# payload.
|
14
14
|
def lock_key(*args)
|
15
|
-
unique_args =
|
15
|
+
unique_args = unique_job_options[:unique_args]
|
16
16
|
lock_args = case unique_args
|
17
17
|
when Proc
|
18
18
|
unique_args.call(*args)
|
@@ -32,24 +32,24 @@ module Resque
|
|
32
32
|
Resque.redis.exists(lock_key(*args))
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
@
|
35
|
+
def unique_job_options
|
36
|
+
@unique_job_options || {}
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
40
|
-
@
|
39
|
+
def unique_job_options=(options)
|
40
|
+
@unique_job_options = options
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
|
43
|
+
def unique_job_mode
|
44
|
+
unique_job_options[:mode].to_sym || :none
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
self.
|
47
|
+
def unique_job(mode=:until_executed, options={})
|
48
|
+
self.unique_job_options = {mode: mode}.merge(options)
|
49
49
|
end
|
50
50
|
|
51
51
|
def before_enqueue_unique_lock(*args)
|
52
|
-
if [:until_executing, :until_executed, :until_timeout].include?(
|
52
|
+
if [:until_executing, :until_executed, :until_timeout].include?(unique_job_mode)
|
53
53
|
return false if locked?(*args)
|
54
54
|
set_lock(*args)
|
55
55
|
end
|
@@ -57,7 +57,7 @@ module Resque
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def around_perform_unique_lock(*args)
|
60
|
-
case
|
60
|
+
case unique_job_mode
|
61
61
|
when :until_executing
|
62
62
|
release_lock(*args)
|
63
63
|
when :while_executing
|
@@ -65,7 +65,7 @@ module Resque
|
|
65
65
|
end
|
66
66
|
yield
|
67
67
|
ensure
|
68
|
-
if [:until_executed, :while_executing].include?(
|
68
|
+
if [:until_executed, :while_executing].include?(unique_job_mode)
|
69
69
|
release_lock(*args)
|
70
70
|
end
|
71
71
|
end
|
@@ -76,8 +76,8 @@ module Resque
|
|
76
76
|
|
77
77
|
def set_lock(*args)
|
78
78
|
is_now_locked = Resque.redis.setnx(lock_key(*args), true)
|
79
|
-
if is_now_locked &&
|
80
|
-
Resque.redis.expire(lock_key(*args),
|
79
|
+
if is_now_locked && unique_job_options[:timeout]
|
80
|
+
Resque.redis.expire(lock_key(*args), unique_job_options[:timeout].to_i)
|
81
81
|
end
|
82
82
|
is_now_locked
|
83
83
|
end
|