Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
Can now GameState::Game#expire
Browse files Browse the repository at this point in the history
Purges stuff from redis
  • Loading branch information
kurtisnelson committed Nov 25, 2013
1 parent 4e23df5 commit 61f7bfa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
20 changes: 11 additions & 9 deletions app/models/game_state/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ def home_score
r.get(key(:home_score)).to_i
end

def set_expiration
@date = ::Game.find(id).start_datetime + 1.day
def expire
@date = Time.now
epoch = @date.to_i
r.pipelined do
lineups.set_expiration(epoch)
inning.set_expiration(epoch)
self.set_expiration(epoch)
set_expiration(epoch)
end
end

Expand All @@ -227,12 +227,14 @@ def pusher(event, data = {})
end

def set_expiration epoch
r.expireat(key :bases, epoch)
r.expireat(key :away, epoch)
r.expireat(key :home, epoch)
r.expireat(key :balls, epoch)
r.expireat(key :strikes, epoch)
r.expireat(key :outs, epoch)
r.expireat(key(:bases), epoch)
r.expireat(key(:away), epoch)
r.expireat(key(:home_score), epoch)
r.expireat(key(:away_score), epoch)
r.expireat(key(:home), epoch)
r.expireat(key(:balls), epoch)
r.expireat(key(:strikes), epoch)
r.expireat(key(:outs), epoch)
end
end
end
4 changes: 4 additions & 0 deletions app/models/game_state/inning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ def top?
def bottom?
!top?
end

def set_expiration epoch
r.expireat(key(:inning), epoch)
end
end
end
4 changes: 2 additions & 2 deletions app/models/game_state/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def get_int_array attr
r.lrange(key(attr), 0, -1).map {|i| i.to_i}
end

def set_expiration
raise "no expiration method"
def set_expiration epoch
puts self.class.to_s + " Missing expiration"
end

def r
Expand Down

0 comments on commit 61f7bfa

Please sign in to comment.