Created
February 28, 2010 20:39
-
-
Save alan/317784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Bluepill | |
module Triggers | |
class EmailNotifier < Bluepill::Trigger | |
def initialize(process, options = {}) | |
@notify_on = [options.delete(:notify_on)] | |
super | |
end | |
def notify(transition) | |
if @notify_on.include?(transition.to_name) | |
send_notification(transition) | |
end | |
end | |
private | |
def send_notification(transition) | |
Pony.mail( | |
:to => Email['recipient'], | |
:subject => "Your process #{self.process.name}", | |
:body => "Your process #{self.process.name}", | |
:content_type => 'text/html', | |
:via => :smtp, | |
:smtp => { | |
:host => "smtp.gmail.com", | |
:port => "587", | |
:auth => :plain, | |
:user => Email['user'], | |
:password => Email['password'], | |
:tls => true | |
} | |
) | |
end | |
end | |
end | |
end | |
Bluepill.application("bookit") do |app| | |
app.process("backend_app") do |process| | |
process.working_dir = ROOT | |
process.start_command = "/usr/bin/env APP_ENV=production script/bookit_ctl start" | |
process.stop_command = "script/bookit_ctl stop" | |
process.restart_command = "/usr/bin/env APP_ENV=production script/bookit_ctl restart" | |
process.pid_file = ROOT + "log/bookit.pid" | |
process.restart_grace_time = 10.seconds | |
process.checks :mem_usage, :every => 5.minutes, :below => 50.megabytes, :times => [3,5] | |
process.checks :email_notifier, :notify_on => :restarting | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment