nikhaldi / exception_notification-rake

Sends mail upon failures in Rake tasks
MIT License
39 stars 14 forks source link

Not working with custom notifiers #9

Open Aetherus opened 9 years ago

Aetherus commented 9 years ago

Hi, nikhaldi

I wrote a custom email notifier:

module ExceptionNotifier
  class DynamicEmailNotifier < EmailNotifier
    def call(exception, options={})
      options.reverse_merge!(exception_recipients: Admin.where(notified: true).pluck(:email))
      super
    end
  end
end

and added the following configuration to config/environments/<env>:

Rails.application.configure do
  # ...
  config.middleware.use ExceptionNotification::Rack,
    dynamic_email: {
        email_prefix: '[EDM2] ',
        sender_address: 'Admin <admin@zzz.zz>',
        # Override default action mailer settings.
        delivery_method: :smtp,
        smtp_settings: {
            address: '127.0.0.1',
            port: 25,
            user_name: 'admin@zzz.zz',
            password: Rails.application.secrets[:sender_password],
            authentication: :plain,
            enable_starttls_auto: true,
            openssl_verify_mode: 'none'
        }
    }
  ExceptionNotifier::Rake.configure
end

It works well when the exceptions are triggered by the HTTP requests, but when the exceptions are from rake tasks, no email is sent, and there is no record in maillog indicating that any email delivery has been tried.

nikhaldi commented 9 years ago

Hi! Which version of the gem are you using?

nikhaldi commented 9 years ago

Also curious where you are defining ExceptionNotifier::DynamicEmailNotifier - are you sure it's being loaded when the rake task is run?