Check whether the delayed job is running in rails

22,330

Solution 1

With Rails 5.x you can ssh into your server and go into the /current folder within your app and run:

RAILS_ENV=production bin/delayed_job status

Solution 2

You can use

RAILS_ENV=production script/delayed_job status 

if you are checking in production mode

Solution 3

The most simple way to check whether delayed_job is running or not, is to check at locked_by field.

This field will contain the worker or process locking/processing the job.

Running Delayed::Job.where('locked_by is not null') will give you some results, if there are jobs running.

Besides that, you can have a clockwork task performing this query, to check at the status.

Hope this helps.

Solution 4

Currently, the best way I can think of to ensure the delayed_job daemon is always running, is to add an initializer to our Rails application that checks if the daemon is running. If it's not running, then the initializer starts the daemon, otherwise, it just leaves it be.

Now the question, therefore, is how do we detect that the Delayed_Job daemon is running from inside a script?

The easy way-

Check for the existence of the daemons PID file (File.exist? ...). If it's there then assume it's running else start it up.

Solution 5

To check the job status etc you can use delayed_job_web gem which enlists all the enqueued jobs. And to ensure that its running all the time install monit. Here's the railscast. Here's more info about how to configure monit for delayed_job

Share:
22,330
Virtual
Author by

Virtual

A beginner! :)

Updated on April 13, 2021

Comments

  • Virtual
    Virtual about 3 years

    I am designing a status page where I need to show whether the delayed job is running. Please help me with a way to find it in the code.

    Am using Rails 3.0.20, ruby 1.8.7 (2011-06-30 patchlevel 352), and delayed_job 3.0.4

  • prasad.surase
    prasad.surase over 10 years
    i m working on EC2 with DJ(Active record). I m using 'mina' for deployment. how can i check if DJ is running or not before starting it. The problem is multiple DJ processes are started whenever i deploy.
  • Yujun Wu
    Yujun Wu over 9 years
    How do you start worker in script? Would script/delayed_job restart work?
  • bayfieldcoder
    bayfieldcoder about 9 years
    On my Rails 4 project, the command was RAILS_ENV=production script/delayed_job status
  • pastullo
    pastullo almost 9 years
    @bayfieldcoder did you upgrade that project from rails 3?
  • bayfieldcoder
    bayfieldcoder over 8 years
    Yes, I did upgrade it from rails 3.