steveklabnik / request_store

Per-request global storage for Rack.
https://github.com/steveklabnik/request_store
MIT License
1.47k stars 87 forks source link

Clear the store after each background job being processed? #65

Open khiav223577 opened 4 years ago

khiav223577 commented 4 years ago

It seems that there is a gem that can deal with Sidekiq, but what about ActiveJob?

https://github.com/steveklabnik/request_store#using-with-sidekiq

A companion library, request_store-sidekiq creates a Sidekiq middleware that will ensure the store is cleared after each job is processed, for security and consistency with how this is done in Rack.

johan-smits commented 4 years ago

It is in the README ...or even ActiveJob backed Sidekiq

khiav223577 commented 4 years ago

It is in the README ...or even ActiveJob backed Sidekiq

Yah, but only with those ActiveJobs backed Sidekiq.

BTW, I use this workaround currently:

# app/jobs/application_job.rb
class ApplicationJob < ActiveJob::Base
  before_perform do
    RequestStore.clear!
  end
end
johan-smits commented 4 years ago

@khiav223577 that sounds like a good generic solution.

My suggestion would be make a PR to update the documentation with your code above.