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

Support for re-enque later, or drop-previous #38

Open
Genkilabs opened this issue Jan 27, 2022 · 2 comments
Open

Support for re-enque later, or drop-previous #38

Genkilabs opened this issue Jan 27, 2022 · 2 comments

Comments

@Genkilabs
Copy link

Hello, I love this gem, thank you.
I have a use case where when a job is enqueued I'd like to keep pushing back the time of a scheduled job until it is executed without being re-requested.
ie.

  • job is scheduled to run in 1 hour.
  • before that job runs it is re-requested
  • I'd like to either push it back to 1 hour from the new request, or, drop it and schedule a new one in 1 hour.

Perhaps I could do this with context to the job that was locking out the requested job?
unique :until_executed, on_conflict: ->(job, locked_job) { locked_job.drop(); job.enqueue(wait: 1.hour) }
or
unique :until_executed, on_conflict: ->(job, locked_job) { locked_job.reenque(wait: 1.hour) }

Any advice on how to best do this?

@akostadinov
Copy link
Contributor

akostadinov commented Jun 16, 2022

You can use on_conflict: :log. Then use the notification:

    ActiveSupport::Notifications.subscribe('conflict.active_job_uniqueness') do
|name, start, finish, id, payload|
      payload[:job].reenque(wait: 1.hour)
    end

@DanAndreasson
Copy link
Contributor

This behavior really surprised me and was the cause of a nasty bug. I assumed that it would retry 5 times as usual.

Should the lock be released before the rescheduling occurs?

  unique :until_executed, lock_ttl: 10.minutes, on_conflict: :log
  retry_on CustomError,
           wait: :exponentially_longer,
           attempts: 5

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