Sidekiq-ActiveRecord

Sidekiq-ORM Project


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

Sidekiq::ActiveRecord::TaskWorker

Back to the documention.

Full Example

class UserMailerTaskWorker < Sidekiq::ActiveRecord::TaskWorker

  sidekiq_task_model :user # or User class
  sidekiq_task_options :identifier_key => :token

  def perform_on_model(options)
    UserMailer.send_confirmation(task_model, options[:new_email])
  end

  # optional
  def not_found_model(token)
    Log.error "User not found for token:#{token}"
  end

  # optional
  def should_perform_on_model?
    task_model.active?
  end

  # optional
  def did_not_perform_on_model
    Log.error "User #{task_model.token} is invalid"
  end

end

Which can be ran by doing:

UserTaskWorker.perform_async(user.id, {:new_email => true})



Full Example With Aliasing

The specified sidekiq_task_model will create method aliases for task_model and all the hook methods, as follows:

class UserMailerTaskWorker < Sidekiq::ActiveRecord::TaskWorker

  sidekiq_task_model :user # or User class
  sidekiq_task_options :identifier_key => :token

  def perform_on_user(options)
    UserMailer.send_confirmation(user, options[:new_email])
  end

  # optional
  def not_found_user(token)
    Log.error "User not found for token:#{token}"
  end

  # optional
  def should_perform_on_user?
    user.active?
  end

  # optional
  def did_not_perform_on_user
    Log.error "User #{user.token} is invalid"
  end

end