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

Use perform_now instead of perform #58

Open
NeilBetham opened this issue Feb 24, 2017 · 4 comments
Open

Use perform_now instead of perform #58

NeilBetham opened this issue Feb 24, 2017 · 4 comments

Comments

@NeilBetham
Copy link

Would it be possible to use ActiveJob's peform_now instead of perform? The main reason I ask is that using peform_now will call all of the ActiveJob callbacks and error handlers. The error handler callback is particularly important for reporting problems to a error reporting system like Sentry. Is there a reason perform was used instead of perform_now?

@MohamedBassem
Copy link

Yes please. I spent 2 hours trying to find why job failures doesn't trigger airbrake notifications until I found that the rescue_from of the ActiveJob is not triggered because Job.new.perform is used instead of perform_now.

@edwardmp
Copy link

edwardmp commented Aug 8, 2017

I agree. Is there any reason perform is used because of perform_now?

@edwardmp
Copy link

edwardmp commented Aug 8, 2017

As a workaround you can do something like this:

class NewRegistrationProcessor
  def perform
    NewRegistrationProcessorJob.perform_now
  end
end

Crono.perform(NewRegistrationProcessor).every 1.minute

But I agree it would be better if perform_now is called by default

Edit: in my case, this still doesn't report the error to Rollbar. It seems Crono catches the error elsewhere:

handle_job_fail(e)

so you would need to monkey patch the handle_job_fail method to get this to work.

@sina-s
Copy link

sina-s commented Sep 8, 2018

I have the exact same use-case, reporting errors to Sentry. I came up with another work around that doesn't need monkey patching Crono. Assuming your jobs are subclass of ApplicationJob, define your perform inside ApplicationJob and change the perform method name to something else (in my case perform!) in your job class. Not sure how graceful this work around is, as it requires to change all of your job classes.

class ApplicationJob < ActiveJob::Base
  def perform
    perform!
  rescue StandardError => e
    Raven.capture_exception(e)
  end 
end
class MyFrequntTask < ApplicationJob
  def perform!
     ...
   end
end

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

No branches or pull requests

4 participants