17

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

Virtual
  • 2,111
  • 5
  • 17
  • 27

6 Answers6

23

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
pastullo
  • 4,171
  • 3
  • 30
  • 36
14

You can use

RAILS_ENV=production script/delayed_job status 

if you are checking in production mode

Shiva
  • 11,485
  • 2
  • 67
  • 84
Niket
  • 1,105
  • 12
  • 15
8

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.

broschb
  • 4,976
  • 4
  • 35
  • 52
Ron
  • 2,215
  • 3
  • 22
  • 30
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.

sjain
  • 23,126
  • 28
  • 107
  • 185
  • 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. – Prasad Surase Nov 29 '13 at 07:38
  • How do you start worker in script? Would script/delayed_job restart work? – Yujun Wu Dec 09 '14 at 08:24
2

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

Community
  • 1
  • 1
benchwarmer
  • 2,764
  • 23
  • 25
0
#!/usr/bin/env ruby

pid = ARGV[0].to_i

begin
  Process.kill(0, pid)
  puts "#{pid} is running"
rescue Errno::EPERM                     # changed uid
  puts "No permission to query #{pid}!";
rescue Errno::ESRCH
  puts "#{pid} is NOT running.";      # or zombied
rescue
  puts "Unable to determine status for #{pid} : #{$!}"
end

Check How can I determine if a different process id is running using Java or JRuby on Linux?

Community
  • 1
  • 1
Zernel
  • 1,487
  • 2
  • 15
  • 27