Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 678
sparkle Avatar asked Oct 16 '25 16:10

sparkle


1 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.

like image 120
johansenja Avatar answered Oct 18 '25 11:10

johansenja



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!