[Awesome Ruby Gem] Use request_store-sidekiq gem to integrate between RequestStore and Sidekiq
request_store-sidekiq
request_store-sidekiq
provide an easy integration between RequestStore
and Sidekiq
.
RequestStore
allows you to easily create threadsafe code, and this middleware for Sidekiq
brings that functionality to Sidekiq workers, or even ActiveJob
backed Sidekiq
.
Installation
You can install it as a gem:
1 | gem install request_store-sidekiq |
or add it into a Gemfile (Bundler):
1 | # madebylotus/request_store-sidekiq: Provides an easy integration between RequestStore and Sidekiq |
Then, run bundle install
.
1 | bundle install |
Usages
If using Rails, the Sidekiq middleware is already inserted into the Sidekiq middleware stack for you automatically and there is nothing to do.
And try the code to this:
1 | def index |
Now no matter Sidekiq workers, or even ActiveJob
backed Sidekiq
you use, you’ll get 1 every time: the storage is local to that worker.
References
[4] request_store | RubyGems.org | your community gem host - https://rubygems.org/gems/request_store/