Sidekiq-ActiveRecord

Sidekiq-ORM Project


Project maintained by sidekiq-orm Hosted on GitHub Pages — Theme by mattgraham

Sidekiq::Activerecord encapsulates common patterns and various interactions between Sidekiq and ActiveRecord.

Common Patterns

If you've been using Sidekiq for a while, you've probably noticed a recurring pattern in your workers:


Sidekiq::ActiveRecord::TaskWorker

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.




Sidekiq::ActiveRecord::ManagerWorker

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.




Documentation

Checkout the project's Wiki Page




Installation

Add this line to your application's Gemfile:

gem 'sidekiq-activerecord', '~> 0.0.5'

And then execute:

$ bundle