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

ActiveJob plugin should reset the notifier before performing the job #1035

Open
whoward opened this issue Mar 20, 2021 · 0 comments
Open

ActiveJob plugin should reset the notifier before performing the job #1035

whoward opened this issue Mar 20, 2021 · 0 comments

Comments

@whoward
Copy link

whoward commented Mar 20, 2021

Hi,
So our Rails application has very low needs for a Job queue and as a result we use the default ActiveJob::QueueAdapters::AsyncAdapter (we are aware of the downsides of this adapter and they're fine for us as our needs are primarily only for maintaining caches which are expired anyways over time).

What we've noticed is that when exceptions are reported to Rollbar the scope seems to be incorrectly set with data from controller actions with the current user set (this doesn't make sense in the context of a Job execution).

I think what's happening is that the thread executes a controller action, which sets the scope, then the thread executes a job which retains the scope from the controller. Alternatively this could also be occurring when the work queue reaches it's capacity, in which case ActiveJob runs the job immediately in the caller thread.

The solution we currently have is to have a before_perform callback defined in ApplicationJob which calls Rollbar.reset_notifier!. Like this:

class ApplicationJob < ActiveJob::Base
  include Rollbar::ActiveJob

  before_perform { |_| Rollbar.reset_notifier! }
end

I'm not sure this is entirely correct because in the case where the queue is filled and the job is run in the caller thread then we should ideally restore the original scope after the job is performed, but I'm not sure how to do this and for the moment the solution above seems to work.

Do you have any thoughts on how best to resolve this?

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

1 participant