resque-throttler 0.1.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/resque/throttler.rb +15 -4
- data/resque-throttler.gemspec +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: 09888d1679af9193b4323ac267b2d1488d911d8a
|
4
|
+
data.tar.gz: 287f898deb3c12a723527fe024645dd63f7821de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3150786f6c903bb11d1a4386ac943c681411f434a6f4bab42ff9d659bc20754ba762273d06d9de80c8b64a323fdb49333a6029dc7c188e4dc421fd9cbe4bde5
|
7
|
+
data.tar.gz: ecd025b6e2946ea1777af977ee399cc97259269820b2c6280dbed93bbec561544dff2a90ee4bca0678120392a47cd8a2c68ed1db2b81e6054ab819dba776d02a
|
data/lib/resque/throttler.rb
CHANGED
@@ -67,14 +67,14 @@ class Resque::Job
|
|
67
67
|
|
68
68
|
def perform_with_throttler
|
69
69
|
if Resque.queue_rate_limited?(self.queue)
|
70
|
-
|
70
|
+
@throttler_uuid = SecureRandom.uuid
|
71
71
|
begin
|
72
72
|
# TODO this needs to be wrapped in a transcation
|
73
|
-
redis.hmset("throttler:jobs:#{
|
74
|
-
redis.sadd("throttler:#{queue}_uuids",
|
73
|
+
redis.hmset("throttler:jobs:#{@throttler_uuid}", "started_at", Time.now.to_i)
|
74
|
+
redis.sadd("throttler:#{queue}_uuids", @throttler_uuid)
|
75
75
|
perform_without_throttler
|
76
76
|
ensure
|
77
|
-
redis.hmset("throttler:jobs:#{
|
77
|
+
redis.hmset("throttler:jobs:#{@throttler_uuid}", "ended_at", Time.now.to_i)
|
78
78
|
end
|
79
79
|
else
|
80
80
|
perform_without_throttler
|
@@ -83,4 +83,15 @@ class Resque::Job
|
|
83
83
|
alias_method :perform_without_throttler, :perform
|
84
84
|
alias_method :perform, :perform_with_throttler
|
85
85
|
|
86
|
+
# This is added for when there is a dirty exit
|
87
|
+
# TODO: testme
|
88
|
+
def fail_with_throttler(exception)
|
89
|
+
if defined?(@throttler_uuid)
|
90
|
+
redis.hmset("throttler:jobs:#{@throttler_uuid}", "ended_at", Time.now.to_i)
|
91
|
+
end
|
92
|
+
fail_without_throttler(exception)
|
93
|
+
end
|
94
|
+
alias_method :fail_without_throttler, :fail
|
95
|
+
alias_method :fail, :fail_with_throttler
|
96
|
+
|
86
97
|
end
|
data/resque-throttler.gemspec
CHANGED