Sunday, September 08, 2013

Clearing Stuck Delayed Jobs

Delayed job had completed its work, for some reason it was still stuck in the queue. To remove it from the queue, on the server run the commands:

Step 1 :

$ RAILS_ENV=production script/delayed_job stop

This will stop the delayed_job process.

Step 2 :

$ pgrep -f delayed_job

This will return no result, therefore confirming that the delayed_job process has been stopped.

Step 3:

Go to rails console in production and run :

> job = Delayed::Job.count
   (0.3ms)  SELECT COUNT(*) FROM `delayed_jobs`
=> 1

> job = Delayed::Job.first
  Delayed::Backend::ActiveRecord::Job Load (0.5ms)  SELECT `delayed_jobs`.* FROM `delayed_jobs` LIMIT 1
=> #
> job.delete