Skip to content

Instantly share code, notes, and snippets.

@entity1991
Forked from denwwer/dj_plugin.rb
Last active August 29, 2015 14:07
Show Gist options
  • Save entity1991/22d2f8aea5fbbba6c376 to your computer and use it in GitHub Desktop.
Save entity1991/22d2f8aea5fbbba6c376 to your computer and use it in GitHub Desktop.
# 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