Skip to content

Instantly share code, notes, and snippets.

@denwwer
Created June 22, 2014 17:18
Show Gist options
  • Save denwwer/515cdec30fde8639def6 to your computer and use it in GitHub Desktop.
Save denwwer/515cdec30fde8639def6 to your computer and use it in GitHub Desktop.
send email if delayed_job job is failed via exception_notification
# Usage
# DJ config
require Rails.root.join('lib', 'dj_plugin.rb')
Delayed::Worker.plugins << Delayed::Plugins::EmailNotify
# lib/dj_plugin.rb
require 'exception_notification'
module Delayed::Plugins
class EmailNotify < ::Delayed::Plugin
module Notify
def error(job, exception)
ExceptionNotifier.notify_exception(exception, email_prefix: '[ERROR] [DJ] ')
super if defined?(super)
end
end
callbacks do |lifecycle|
lifecycle.before(:invoke_job) do |job|
payload = job.payload_object
payload = payload.object if payload.is_a? Delayed::PerformableMethod
payload.extend Notify
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment