resque-uniq 0.0.8 → 0.0.9
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 +8 -8
- data/Gemfile +1 -1
- data/lib/resque-uniq/version.rb +1 -1
- data/lib/resque/plugins/unique_job.rb +18 -4
- data/test/unique_job_test.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDc0ZDlmZTMyMzE4MWM5ODI5ZDFlNDEwNmQ4ZWRlYTFlYmYyM2JmMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGEyYmYyZTA5Mjk4OWMzYjM3MmRlZDk3MDJmMjZkOWEwYjg1ZWY1ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2QxNWQ2OTYwZTQzNTk3ODlmY2VkMjEwMWE5YWEzZGU0Y2NhZTI2YTMyODYw
|
10
|
+
YmJiNTk5M2Y1YjhjM2FkNzE3ZmUxYzQ1MGQ2MjE4MmUzYzkyOTI0NGUwZDk1
|
11
|
+
MDBmYzE4NjFlNzI0YjVhNWJiYzc1MmQ5ZDVkODc3YjE2MWY1NzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTIxMmNjYzc5MmJhYWM5NzZkMzRmMTJmZDkzMDQzYWFhNTQ5M2VlMjAzNzE0
|
14
|
+
YTRhMDA0OTM1MjNmMzZiYmQyMTZhYTg5ZjhjNmRjMTBjOTg3Y2MyMmI3Njg4
|
15
|
+
MjNiNWI2YTE3YjgyOGRjZWM3NTI1ZjU4NmNkMWMzMTNjOTAwZDg=
|
data/Gemfile
CHANGED
data/lib/resque-uniq/version.rb
CHANGED
@@ -21,10 +21,10 @@ module Resque
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def stale_lock?(lock)
|
24
|
-
return false unless
|
24
|
+
return false unless get_lock(lock)
|
25
25
|
|
26
26
|
rlock = run_lock_from_lock(lock)
|
27
|
-
return false unless
|
27
|
+
return false unless get_lock(rlock)
|
28
28
|
|
29
29
|
Resque.working.map {|w| w.job }.map do |item|
|
30
30
|
begin
|
@@ -39,15 +39,29 @@ module Resque
|
|
39
39
|
true
|
40
40
|
end
|
41
41
|
|
42
|
+
def ttl
|
43
|
+
instance_variable_get(:@unique_lock_autoexpire) || respond_to?(:unique_lock_autoexpire) && unique_lock_autoexpire
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_lock(lock)
|
47
|
+
lock_value = Resque.redis.get(lock)
|
48
|
+
set_time = lock_value.to_i
|
49
|
+
if ttl && set_time && (set_time > Time.now.to_i - ttl)
|
50
|
+
Resque.redis.del(lock)
|
51
|
+
nil
|
52
|
+
else
|
53
|
+
lock_value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
42
57
|
def before_enqueue_lock(*args)
|
43
58
|
lock_name = lock(*args)
|
44
59
|
if stale_lock? lock_name
|
45
60
|
Resque.redis.del lock_name
|
46
|
-
Resque.redis.del
|
61
|
+
Resque.redis.del run_lock_from_lock(lock_name)
|
47
62
|
end
|
48
63
|
not_exist = Resque.redis.setnx(lock_name, Time.now.to_i)
|
49
64
|
if not_exist
|
50
|
-
ttl = instance_variable_get(:@unique_lock_autoexpire) || respond_to?(:unique_lock_autoexpire) && unique_lock_autoexpire
|
51
65
|
if ttl && ttl > 0
|
52
66
|
Resque.redis.expire(lock_name, ttl)
|
53
67
|
end
|
data/test/unique_job_test.rb
CHANGED
@@ -27,6 +27,7 @@ class UniqueJobTest < Test::Unit::TestCase
|
|
27
27
|
|
28
28
|
def setup
|
29
29
|
Resque.remove_queue(Resque.queue_from_class(Job))
|
30
|
+
Resque.remove_queue(Resque.queue_from_class(AutoexpireLockJob))
|
30
31
|
Resque.redis.keys('*:UniqueJobTest::*').each {|k| Resque.redis.del(k) }
|
31
32
|
end
|
32
33
|
|
@@ -93,4 +94,9 @@ class UniqueJobTest < Test::Unit::TestCase
|
|
93
94
|
assert_equal 2, Resque.size(Resque.queue_from_class(ExtendedAutoExpireLockJob))
|
94
95
|
end
|
95
96
|
|
97
|
+
def test_cleans_up_old_lock_during_enqueue
|
98
|
+
Resque.redis.set(AutoexpireLockJob.lock(123), Time.now.to_i + 100)
|
99
|
+
Resque.enqueue(AutoexpireLockJob, 123)
|
100
|
+
assert_equal 1, Resque.size(Resque.queue_from_class(AutoexpireLockJob))
|
101
|
+
end
|
96
102
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-uniq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trung Duc Tran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|