Sidekiq-ORM Project
Sidekiq::Activerecord encapsulates common patterns and various interactions between Sidekiq and ActiveRecord.
If you've been using Sidekiq for a while, you've probably noticed a recurring pattern in your workers:
A very conventional pattern, is to have a worker that gets a model identifier, loads it and runs some custom logic on the model.
TaskWorker
provides a simple and clean interface, which reduces the boilerplate and exposes only the custom logic.
Here's a simple example:
class UserTaskWorker < Sidekiq::ActiveRecord::TaskWorker
sidekiq_task_model :user # or User
def perform_on_user
UserService.run(user)
end
end
For a more see the TaskWorker documentation.
Another fairly common Sidekiq::Worker
pattern, is a parent worker which goes over a model collection and enqueues a child worker for each model in the collection.
Here's a simple example:
# Parent Worker
class UserSyncer < Sidekiq::ActiveRecord::ManagerWorker
sidekiq_delegate_task_to :user_task_worker # or UserTaskWorker
end
Then, just call the worker with the model collection:
UserSyncer.perform_query_async(User.active)
For a more see the ManagerWorker documentation.
Checkout the project's Wiki Page
Add this line to your application's Gemfile:
gem 'sidekiq-activerecord', '~> 0.0.5'
And then execute:
$ bundle