Search code examples
ruby-on-railsrubyruby-on-rails-4resque

Check if a resque job with specific args is pending in queue


For example I enqueued a job as so

Resque.enqueue(MyJob, user.id)

Before en-queueing another job with the same user.id I would like to check if there already exists a job with that user id in the queue.

I hope there is some syntax like:

Resque.queue('MyQueue').has_pending_job(MyJob, user.id)

Solution

  • I don't think there's such thing, you can achieve the same with multiple options

    1. You can have the has_pending_jobs attribute in the user, update it to true when the job starts and false when it ends

    2. use the resque-status extension https://github.com/quirkey/resque-status to keep track of the job_ids that are en queued for a certain user

    3. use separate queue for each user (this isn't scalable) and check if there's something in the queue for the user or not