Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sidekiq-unique-jobs gem

I'm trying to use the sidekiq-unique-jobs but honestly can't get it to do anything it's supposed to do. I'm trying to not be able to queue the same job multiple times (while it's already in the queue or running), but as you see here, I kick off a worker with the same ID 3 times and it runs each time.

Rails 5.2.1 Sidekiq 6.0.6

Any ideas?

Here's the worker:

class RefreshLoginWorker

  include Sidekiq::Worker
  include Sidekiq::Status::Worker

  sidekiq_options queue: 'credentials', :retry => false, lock: :until_executed

  def perform item_id
    sleep 5
  end

end

Here we kick off some job one after another:

irb(main):016:0> RefreshLoginWorker.perform_async 20
=> "4e83f7a419b9aa047860af77"
irb(main):017:0> RefreshLoginWorker.perform_async 20
=> "682776c2fb45866f35cbf87f"
irb(main):018:0> RefreshLoginWorker.perform_async 20
=> "962dc0bae18cfc4ede6aea18"

Sidekiq log:

2020-07-18T17:30:48.468Z pid=561643 tid=gpbejyaar class=RefreshLoginWorker jid=4e83f7a419b9aa047860af77 INFO: start
2020-07-18T17:30:49.060Z pid=561643 tid=gpbejy9vf class=RefreshLoginWorker jid=682776c2fb45866f35cbf87f INFO: start
2020-07-18T17:30:53.469Z pid=561643 tid=gpbejyaar class=RefreshLoginWorker jid=4e83f7a419b9aa047860af77 elapsed=5.001 INFO: done
2020-07-18T17:30:53.470Z pid=561643 tid=gpbejyaar class=RefreshLoginWorker jid=962dc0bae18cfc4ede6aea18 INFO: start
2020-07-18T17:30:54.061Z pid=561643 tid=gpbejy9vf class=RefreshLoginWorker jid=682776c2fb45866f35cbf87f elapsed=5.001 INFO: done
2020-07-18T17:30:58.471Z pid=561643 tid=gpbejyaar class=RefreshLoginWorker jid=962dc0bae18cfc4ede6aea18 elapsed=5.001 INFO: done
like image 849
99miles Avatar asked Jul 18 '20 17:07

99miles


People also ask

How many jobs can Sidekiq handle?

Today Sidekiq uses a default concurrency of 25. These means Sidekiq will spawn 25 worker threads and execute up to 25 jobs concurrently in a process.

Is Sidekiq a FIFO?

Sidekiq reads jobs from a Redis queue, using the First In First Out (FIFO) model, to process jobs.

How do I get a job on Sidekiq?

To test your Sidekiq Worker jobs array, run WorkerNameHere.jobs in terminal and see if it contains your job with your jid. If it does, then it was enqueued in Sidekiq to be run as a job.


1 Answers

Firstly use gem 'sidekiq-unique-jobs' and then bundle. After installation you should enable sidekiq-unique-jobs with SidekiqUniqueJobs.config.enabled. For more details follow sidekiq-unique-jobs

like image 159
Shashank Tripathi Avatar answered Oct 06 '22 22:10

Shashank Tripathi