Ask A Question


You’re not receiving notifications from this thread.

How to debounce ActiveJobs?

Matthias Orgler asked in Rails

How can I debounce jobs in ActiveJob?

Why I need this:
Events in my Rails app can trigger the same job independently from multiple places. But I want this job to run only once – only running the last job scheduled. I want to cancel all earlier jobs to save resources. Here is an example:

Job 1: Re-render file x
Job 2: Re-render file x
Job 3: Re-render file x
=> cancel job 1+2, only execute job 3

What I found:
Found, which implements this for Sidekiq. But I can't figure out how to do it in ActiveJob directly.

Is there a way to debounce jobs in ActiveJob?


Possibly this with a supported backend queue?

I think when you enqueue a job it gives you back an ID. You could probably save that ID to the model that's being processed and look for a match when the job starts to only allow that Job ID to do the processing.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 84,256+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.