Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How :until_executing works ? Run job only once and discard new jobs while another job is executing #226

Closed
maxivak opened this issue May 26, 2017 · 4 comments
Milestone

Comments

@maxivak
Copy link

maxivak commented May 26, 2017

I have this worker with :until_executing option

class MyWorker
  include Sidekiq::Worker
  sidekiq_options queue: 'provision', retry: 20, unique: :until_executing


  def perform(arg1=0)
    t = Time.now.utc

    puts("****** TASK *********. start  #{t}")
    sleep 120
    puts("****** TASK DONE *********. start  #{t}")

  end
end


and I run task multiple times

MyWorker.perform_async - job1
MyWorker.perform_async - job2
MyWorker.perform_async - job3

I expect that the job will run only once since it is a long job (see sleep for 2 min) and two other jobs will be dropped.
Documentation says this about :until_executing
"Any jobs added until the first one of the same arguments has been unlocked will just be dropped."

So I expect while job1 is running and I add job2 and job3 - these jobs would be dropped and never executed.
But I see in Sidekiq log that all three job are executing:

****** TASK *********. start 2017-05-26 15:02:02 UTC

2017-05-26T15:02:03.176Z 22991 TID-2ceuc MyWorker JID-81edb17b697466a2e4f203ae INFO: start
****** TASK *********. start 2017-05-26 15:02:03 UTC

2017-05-26T15:02:04.227Z 22991 TID-ov4gneq9s MyWorker JID-0e65f81c5b718e1e22aaa8b8 INFO: start
****** TASK *********. start 2017-05-26 15:02:04 UTC

How to make new jobs dropped while the first job is executing?

@maxivak maxivak changed the title How :until_executing works ? How :until_executing works ? Run job only once and discard new jobs while another job is executing May 26, 2017
@joshuacronemeyer
Copy link

Hi, I'm just trying to get my head around all the different lock types myself. :) It looks like you are looking for sidekiq_options unique: :until_executed until_executed will maintain the lock until the job is successfully executed.

@maxivak
Copy link
Author

maxivak commented Oct 6, 2017

I don't what to just maintain the lock until the job is successfully executed. I want all other jobs to be dropped and never executed if these jobs are added while the first job is executing.
With :until_executed job1, job2 and job3 will be run in sequence. I want to run job1 and NOT run job2, job3 since they are added while job1 was running.

It is confusing in documentation about :until_executing
"Any jobs added until the first one of the same arguments has been unlocked will just be dropped."

Do you have any mechanism to skip (drop/delete) job? Or a job will be executed in any cases, only the time of running the job depends on locks ?

@mhenrixon
Copy link
Owner

mhenrixon commented Oct 6, 2017

@maxivak with :until_executed it will lock until the job is executed meaning all jobs that are attempted to be put on the queue until the first job is unlocked will just be dropped and never ever executed. You are confusing it with :while_executing. While the job is locked all other jobs with the same arguments will be dropped and never executed.

@mhenrixon
Copy link
Owner

I've clarified this a little better in the README. Will close this issue now but just ping me if you have any further questions.

@mhenrixon mhenrixon added this to the Version 6.0 milestone Jun 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants