Bendangelo Blog

Using Sidekiq Iteration and Unique Jobs

Dec 11, 2023 1 minute read

This will remove the sidekiq iteration hash from the arguments, so the sidekiq job will appear unique to unique jobs.

Couldn’t find this online so here is a quick fix.

class MyJob
  include Sidekiq::Job
  include SidekiqIteration::Iteration

  sidekiq_options queue: :default, lock: :until_and_while_executing, on_conflict: :reject

  def self.lock_args args
    if args.last.is_a?(Hash) && args.last.key?("sidekiq_iteration")
      args.take(args.length - 1)
    else
      args
    end
  end

  # ...

Refs

https://github.com/mhenrixon/sidekiq-unique-jobs https://github.com/fatkodima/sidekiq-iteration

Related Posts