redis-scheduler 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/redis-scheduler.rb +10 -14
- metadata +2 -2
data/lib/redis-scheduler.rb
CHANGED
@@ -120,22 +120,18 @@ private
|
|
120
120
|
## zset yourself.
|
121
121
|
class InvalidEntryException < StandardError; end
|
122
122
|
def nonblocking_get descriptor
|
123
|
-
|
123
|
+
loop do
|
124
124
|
@redis.watch @queue
|
125
125
|
entry, at = @redis.zrangebyscore @queue, 0, Time.now.to_f, :withscores => true, :limit => [0, 1]
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
throw :cas_retry
|
136
|
-
end
|
137
|
-
[item, processing_descriptor, Time.at(at.to_f)]
|
138
|
-
end
|
126
|
+
break unless entry
|
127
|
+
entry =~ /^\d+:(\S+)$/ or raise InvalidEntryException, entry
|
128
|
+
item = $1
|
129
|
+
descriptor = Marshal.dump [item, Time.now.to_i, descriptor]
|
130
|
+
@redis.multi do # try and grab it
|
131
|
+
@redis.zrem @queue, entry
|
132
|
+
@redis.sadd @processing_set, descriptor
|
133
|
+
end and break [item, descriptor, Time.at(at.to_f)]
|
134
|
+
sleep CAS_DELAY # transaction failed. retry!
|
139
135
|
end
|
140
136
|
end
|
141
137
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-28 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A basic chronological scheduler for Redis. Add work items to be processed
|
15
15
|
at specific times in the future, and easily retrieve all items that are ready for
|