Created
August 16, 2011 21:22
-
-
Save cmhobbs/1150207 to your computer and use it in GitHub Desktop.
Resque multiple failure notifier via postmark
This file contains hidden or 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
# this goes in lib/resque/failure/notifier.rb | |
require 'resque/failure/multiple' | |
require 'resque/failure/redis' | |
require 'postmark' | |
require 'mail' | |
module Resque | |
module Failure | |
class Notifier < Base | |
class << self | |
attr_accessor :smtp, :sender, :recipients | |
end | |
def self.configure | |
yield self | |
Resque::Failure.backend = self unless Resque::Failure.backend == Resque::Failure::Multiple | |
end | |
def save | |
message = Mail.new | |
# FIXME stash the api key elsewhere | |
message.delivery_method(Mail::Postmark, :api_key => "YOUR-SUPER-SECRET-POSTMARK-KEY-HERE") | |
message.from = self.class.sender | |
message.to = self.class.recipients | |
message.subject = "Resque: #{exception}" | |
message.content_type = "text/html" | |
# FIXME do something other than a here doc, this is ugly | |
message.body = <<EOT | |
Queue: #{queue} | |
Worker: #{worker} | |
#{payload.inspect} | |
#{exception} | |
#{exception.backtrace.join("\n")} | |
EOT | |
# pull the trigger | |
message.deliver | |
end | |
end | |
end | |
end |
This file contains hidden or 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
# this goes in lib/tasks/resque.rake | |
require 'resque/failure/notifier' | |
require 'resque/failure/multiple' | |
require 'resque/failure/redis' | |
ENV['JOBS_PER_FORK'] ||= '1' | |
namespace :resque do | |
task :setup => :environment do | |
Resque.schedule = YAML.load_file("#{Rails.root}/config/resque_schedule.yml") | |
Resque.after_fork do |job| | |
ActiveRecord::Base.establish_connection | |
end | |
Resque::Failure::Notifier.configure do |config| | |
config.sender = "[email protected]" | |
config.recipients = %w{[email protected] [email protected] [email protected]} | |
end | |
Resque::Failure::Multiple.classes = [Resque::Failure::Redis, Resque::Failure::Notifier] | |
Resque::Failure.backend = Resque::Failure::Multiple | |
end | |
end |
This was for a proprietary project, so I can't copy and paste the exact file, but there was no voodoo in it. It was basically several definitions in the following format:
refresh_network_statistics:
cron: "0 1 * * *"
class: NetworkRefreshDispatcher
queue: 'network_refresh_dispatch'
args: 'refresh_stats'
description: "This job refreshes statistics for all enabled networks"
I'm not sure how your question is pertinent to the blog post referencing this gist. Were you trying to figure out how to use multiple failure backends?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Chris, curious as to what's in
resque_schedule.yml
- thanks!