About
stay_awake requests websites periodically. It's written especially for Heroku, that puts applications to sleep when there are no requests coming in.
Installation
Gem
$ gem install stay_awake
Bundler
gem 'stay_awake'Bundler (head)
gem 'stay_awake', :github => 'tbuehlmann/stay_awake'Usage
buzzer = StayAwake.configure do |c|
c.app_name = 'app_name'
end
buzzer.buzzSinatra
Put the StayAwake.configure block inside Sinatra's configure block, run buzz and you're done:
# app.rb
class App < Sinatra::Base
configure :production do
StayAwake.configure do |c|
c.app_name = 'app_name'
end.buzz
end
# …
endRails
Put the StayAwake.configure block inside an initializer, run buzz and you're done:
# config/initializers/stay_awake.rb
if Rails.env.production?
StayAwake.configure do |c|
c.app_name = 'app_name'
end.buzz
endConfiguration Defaults
| Configuration | Type | Default |
|---|---|---|
app_name |
String |
nil |
url |
string |
nil |
request_method |
Symbol |
:head |
interval |
Integer |
300 |
logger |
Logger |
Logger.new(STDOUT) |
strategy |
Class |
StayAwake.strategies |
You can either use app_name or url, but url has precedence over app_name. If just app_name is given, it will be translated to http://app_name.herokuapp.com/.
strategy takes a single Class or Array of Classes that mixed in the Strategy Module. If an Array is given, each Strategy is tested for availability. The first available Strategy will be used for buzzing.
When using EM-HTTP-Request, the buzzing will begin on the next_tick. When using httparty or Net::HTTP, buzzing will begin immediately (using a Thread).