Active Job : How to check if same job has already been scheduled

Viewed 1233

I am using Rails Active Job with Resque and I don't want to schedule twice the same job (same arguments). Job is triggered by user.

How can check this before performing the job?

2 Answers

There is a likely a reason that this is not super straightforward - it is worth making jobs idempotent, so that they can be run multiple times. If a job fails or restarts, it may end up running again.

https://github.com/mperham/sidekiq/wiki/Best-Practices#2-make-your-job-idempotent-and-transactional (I am more used to sidekiq than resque, but the principles are the same)

A better way of structuring it might be for the job to store a value somewhere in the database, and for the job to read that value and determine whether it should perform an action or exit early.

Related