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
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
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
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.
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.
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
#!/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?