Skip to content

Commit

Permalink
Use gem name in cache key ('_' => '-')
Browse files Browse the repository at this point in the history
  • Loading branch information
ndbroadbent committed Sep 19, 2012
1 parent 5ec0cc7 commit f54a2eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions lib/heroku/autoscale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def call(env)
# Use either cache or instance variable to store last_scaled
def last_scaled
if supported_cache?
Rails.cache.read "heroku_autoscale:last_scaled"
Rails.cache.read "heroku-autoscale:last_scaled"
else
@last_scaled
end
end

def last_scaled=(time)
if supported_cache?
Rails.cache.write "heroku_autoscale:last_scaled", time
Rails.cache.write "heroku-autoscale:last_scaled", time
else
@last_scaled = time
end
Expand Down Expand Up @@ -109,14 +109,14 @@ def supported_cache?
end

def obtain_lock
return false if Rails.cache.read "heroku_autoscale:lock"
return false if Rails.cache.read "heroku-autoscale:lock"
# Expire lock in 30 seconds, in case something
# happens to the server and it can't release the lock
Rails.cache.write "heroku_autoscale:lock", true, :expires_in => 30
Rails.cache.write "heroku-autoscale:lock", true, :expires_in => 30
end

def release_lock
Rails.cache.delete "heroku_autoscale:lock"
Rails.cache.delete "heroku-autoscale:lock"
end
end
end
14 changes: 7 additions & 7 deletions spec/heroku/autoscale_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ def noop
heroku.should_receive(:set_dynos).once
app.stub(:heroku).and_return(heroku)

cache.should_receive(:read).with("heroku_autoscale:last_scaled").and_return(Time.now - 60)
cache.should_receive(:read).with("heroku_autoscale:lock").and_return(nil)
cache.should_receive(:write).with("heroku_autoscale:lock", true, {:expires_in => 30}).and_return(true)
cache.should_receive(:write).with("heroku_autoscale:last_scaled", anything)
cache.should_receive(:delete).with("heroku_autoscale:lock")
cache.should_receive(:read).with("heroku-autoscale:last_scaled").and_return(Time.now - 60)
cache.should_receive(:read).with("heroku-autoscale:lock").and_return(nil)
cache.should_receive(:write).with("heroku-autoscale:lock", true, {:expires_in => 30}).and_return(true)
cache.should_receive(:write).with("heroku-autoscale:last_scaled", anything)
cache.should_receive(:delete).with("heroku-autoscale:lock")
app.call({ "HTTP_X_HEROKU_QUEUE_WAIT_TIME" => 101 })

cache.should_receive(:read).with("heroku_autoscale:last_scaled").and_return(Time.now - 60)
cache.should_receive(:read).with("heroku_autoscale:lock").and_return(true)
cache.should_receive(:read).with("heroku-autoscale:last_scaled").and_return(Time.now - 60)
cache.should_receive(:read).with("heroku-autoscale:lock").and_return(true)
cache.should_not_receive(:write)
cache.should_not_receive(:delete)
app.call({ "HTTP_X_HEROKU_QUEUE_WAIT_TIME" => 9 })
Expand Down

0 comments on commit f54a2eb

Please sign in to comment.