Skip to content

Instantly share code, notes, and snippets.

@assaf
Created February 1, 2010 00:04
Show Gist options
  • Save assaf/291329 to your computer and use it in GitHub Desktop.
Save assaf/291329 to your computer and use it in GitHub Desktop.
require "resque"
require "resque/failure/multiple"
require "resque/failure/redis"
# Configure Resque connection from config/redis.yml. This file should look
# something like:
# development: localhost:6379
# test: localhost:6379:15
# production: localhost:6379
Resque.redis = YAML.load_file(Rails.root + 'config/redis.yml')[Rails.env]
module Resque
module Failure
# Logs failure messages.
class Logger < Base
def save
Rails.logger.error detailed
end
def detailed
<<-EOF
#{worker} failed processing #{queue}:
Payload:
#{payload.inspect.split("\n").map { |l| " " + l }.join("\n")}
Exception:
#{exception}
#{exception.backtrace.map { |l| " " + l }.join("\n")}
EOF
end
end
# Emails failure messages.
# Note: uses Mail (default in Rails 3.0) not TMail (Rails 2.x).
class Notifier < Logger
def save
text, subject = detailed, "[Error] #{queue}: #{exception}"
Mail.deliver do
from "error@ ... domain ..."
to "... that would be you ..."
subject subject
text_part do
body text
end
end
rescue
puts $!
end
end
end
end
Resque::Failure::Multiple.configure do |multi|
# Always stores failure in Redis and writes to log
multi.classes = Resque::Failure::Redis, Resque::Failure::Logger
# Production/staging only: also email us a notification
multi.classes << Resque::Failure::Notifier if Rails.env.production? || Rails.env.staging?
end
@barmstrong
Copy link

Ending up using this instead: https://github.com/anandagrawal84/resque_failed_job_mailer

Seemed to work with existing SMTP settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment