Skip to content
Browse files

FIXED: Bluth::TimingBelt.notch now caches notches by absolute time (n…

…ot just HH:MM)
  • Loading branch information...
1 parent 0faf7c3 commit ffaf1fe7f20ffc587d21034f2d0cb9c5fadee12f @delano committed
Showing with 11 additions and 10 deletions.
  1. +2 −1 CHANGES.txt
  2. +7 −6 lib/bluth/timingbelt.rb
  3. +2 −3 try/30_timingbelt_try.rb
View
3 CHANGES.txt
@@ -1,7 +1,8 @@
BLUTH, CHANGES
-#### 0.7.2 (2011-03-??) ###############################
+#### 0.7.2 (2011-04-10) ###############################
+* FIXED: Bluth::TimingBelt.notch now caches notches by absolute time (not just HH:MM)
* CHANGE: Gracefully rescue Errno::ECONNREFUSED and try to reconnect
* ADDED: Bluth::Worker.reconnect!
* ADDED: Bluth::Worker.onerror
View
13 lib/bluth/timingbelt.rb
@@ -65,18 +65,19 @@ def stamp mins=0, time=now
(time + (mins*60)).strftime('%H:%M')
end
def notch mins=0, filter=nil, time=now
+ cache_key = [now(mins, time).to_i, filter].join(':')
key = rediskey(stamp(mins, time), filter)
@notchcache ||= {}
- if @notchcache[key].nil?
- @notchcache[key] ||= Familia::Set.new key,
+ if @notchcache[cache_key].nil?
+ @notchcache[cache_key] ||= Familia::Set.new key,
:ttl => 2*60*60, # 2 hours
:extend => Bluth::TimingBelt::Notch,
:db => Bluth::TimingBelt.db
- @notchcache[key].stamp = stamp(mins, time)
- @notchcache[key].filter = filter
- @notchcache[key].time = now(mins, time)
+ @notchcache[cache_key].stamp = stamp(mins, time)
+ @notchcache[cache_key].filter = filter
+ @notchcache[cache_key].time = now(mins, time)
end
- @notchcache[key]
+ @notchcache[cache_key]
end
def priority minutes=2, filter=nil, time=now
(0..minutes).to_a.reverse.collect { |min| notch(min*-1, filter, time) }
View
5 try/30_timingbelt_try.rb
@@ -9,11 +9,11 @@
## Knows now
Bluth::TimingBelt.now(0, @now).to_s
-#=> '2011-02-14 00:00:00 UTC'
+#=> RUBY_VERSION <= '1.9' ? 'Mon Feb 14 00:00:00 UTC 2011' : '2011-02-14 00:00:00 UTC'
## Now can have an offset
Bluth::TimingBelt.now(5, @now).to_s
-#=> '2011-02-14 00:05:00 UTC'
+#=> RUBY_VERSION <= '1.9' ? 'Mon Feb 14 00:05:00 UTC 2011' : '2011-02-14 00:05:00 UTC'
## Can create a timestamp
Bluth::TimingBelt.stamp 0, @now
@@ -94,7 +94,6 @@
## Can calculate the difference between two notches
notch1 = Bluth::TimingBelt.notch
notch2 = Bluth::TimingBelt.notch 67
-puts notch2.name
notch2 - notch1
#=> 67

0 comments on commit ffaf1fe

Please sign in to comment.
Something went wrong with that request. Please try again.