ruby-on-railsamazon-ec2delayed-jobstart-stop-daemon

Delayed jobs stops after some time


I have an application which relies heavily on delayed jobs. So I have setup two servers, one of which servers up the application (m3.medium ec2 instance) while other one runs my delayed jobs(t2.micro ec2 instance). I have created a start and stop script for the delayed jobs. This is where I am facing issues. Delayed jobs run smoothly but the problem is that they stop automatically after some time. So everytime they stop I have to manually start them again. I have no clue whatsoever why they stop in the middle of processing a job.

So basically I have two questions:

  1. What can I do so that the jobs don't stop, or if they do they start automatically immediately/or after some time?

  2. How can I make them start automatically on instance reboot/start?

I have looked at many similar questions, but none seem to help.

Any advice appreciated.

Edit 1:

My start/stop script for the delayed jobs.

set -e

# drop privs if necessary
if [ "$(id -u)" == "0" ]; then
  exec su $(stat -c %U $(dirname $(readlink -f $0))/../config/environment.rb) -c "/bin/bash $0 $@"
  exit -1;
fi

# switch to app root
cd $(dirname $(readlink -f $0))/..

# set up config
if [ -e "config/GEM_HOME" ]; then
  export GEM_HOME=$(cat config/GEM_HOME)
fi
#export GEM_HOME=/path/to/gem/home
export RAILS_ENV=production

# run delayed jobs
exec script/delayed_job $@

# following an article I have tried adding the following code restart on crash.

# restarting the service 
respawn

#Give up if restart occurs 10 times in 90 seconds.
respawn limit 10 90

Solution

  • Its seem you might be having memory issue which is killing it. you can try Monit to automatically start job if its killed

    ref: http://railscasts.com/episodes/375-monit

    Alternative: You may also use sidekiq instead of delayed job