ApartmentJob
ActiveJob support for Apartment Gem. Its a small wrapper around ActiveJob that takes care of storing the current tenant that a job is enqueued within and make sure to switch to it when the job is being processed. No need to pass around current tenant details to your background jobs.
ApartmentJob uses ActiveJob's public api for handling current tenant details, so it is not tied to any specific queuing adapter. It should work fine with all queue adapters supported by ActiveJob.
Installation
Add this line to your application's Gemfile:
gem 'apartment_job'
And then execute:
$ bundle
Or install it yourself as:
$ gem install apartment_job
Usage
That's it. Each job that is queued will also save Apartment::Tenant.current
value along with it. Then when the server pops it, it will run the job within an Apartment::Tenant.switch
block using the tenant that was active when the job was enqueued.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
License
The gem is available as open source under the terms of the MIT License.