Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background notifications for Shoryuken/ActiveJob #368

Open
Startouf opened this issue Sep 22, 2016 · 2 comments
Open

Background notifications for Shoryuken/ActiveJob #368

Startouf opened this issue Sep 22, 2016 · 2 comments
Labels

Comments

@Startouf
Copy link

Any hope to see some adaptation for shoryuken ? Or even better, for ActiveJob ? (and if it's supposed to be working already, I can fill out a better bug report)

@FLarra FLarra added the feature label Jan 24, 2019
@drselump14
Copy link

would love to have it

@coezbek
Copy link

coezbek commented Dec 8, 2021

It seems harder than it should be to integrate with ActiveJob.

How are others solving it:

If you don't care for perfection, one way to go is to add the following to your ApplicationJob:

# app/jobs/application_job.rb
class ApplicationJob < ActiveJob::Base
  # Automatically retry jobs that encountered a deadlock
  # retry_on ActiveRecord::Deadlocked

  # Most jobs are safe to ignore if the underlying records are no longer available
  # discard_on ActiveJob::DeserializationError

  rescue_from StandardError do |exception|
    ExceptionNotifier.notify_exception(exception)
  end

end

Note: Since rescue_from stops with the first handler which handles an exception there is no way to continue with other rescue_from handlers. You could go another path with around_perform, but then all helper methods such as retry_on and discard_on will not prevent exceptions from being sent.

To decorate the failure a bit more (by giving the name of the failed job for instance) you can also do:

  rescue_from StandardError do |exception|
    begin
      raise StandardError, "#{self.class.name} failed: (#{exception.class}) #{exception}", exception.backtrace
    rescue => e
      ExceptionNotifier.notify_exception(e)
    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants