Writing · 2023 · 1 min

Using Sidekiq Iteration and Unique Jobs

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

Comments

No comments yet. Be the first.

Leave a comment

Plain text. Comments are reviewed before they appear; your email is never asked for.