Skip to content

Encapsulates common patterns and various interactions between Sidekiq and ActiveRecord.

License

Notifications You must be signed in to change notification settings

sidekiq-orm/sidekiq-activerecord

Repository files navigation

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

Build Status


Common Patterns

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 documention.


Another farily 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 documention.


Documention

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

Contributing

  1. Fork it ( http://github.com/sidekiq-orm/sidekiq-activerecord/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Encapsulates common patterns and various interactions between Sidekiq and ActiveRecord.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages