0

If I run my script manually, i.e. sh /home/deploy/scripts/cleanup.sh, everything works fine, but when executing the same script via crontab, the delayed_job part does not work (everything else works!)

# Restart all processes
cd ~/apps/kosher/current
~/.rvm/bin/rvm default do bundle exec pumactl -S /home/deploy/apps/kosher/shared/tmp/pids/puma.state -F /home/deploy/apps/kosher/shared/puma.rb stop
~/.rvm/bin/rvm default do bundle exec puma -C /home/deploy/apps/kosher/shared/puma.rb --daemon
if RAILS_ENV=production bin/delayed_job restart
 then 
  echo "kosher delayed_job restarted" >> /home/deploy/scripts/cleanup.log
 else
  echo "kosher delayed_job restart failed" >> /home/deploy/scripts/cleanup.log
fi

I tried to use ~/.rvm/bin/rvm default do bundle exec bin/delayed_job -n 1 restart instead of RAILS_ENV=production bin/delayed_job restart, but then I receive an error, stating, that I'm missing the listen-gem:

bundler: failed to load command: bin/delayed_job (bin/delayed_job)
LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile

However, my Gemfile does indeed include the gem.

Why can't I restart delayed_job via crontab?

mohnstrudel
  • 639
  • 8
  • 22
  • You should run this command from the application directory. Try this - `cd /path/to/application/dir && RAILS_ENV=production bin/delayed_job restart` – Ashik Salman Feb 27 '18 at 06:48
  • Otherwise give full path for delayed job binary file - `RAILS_ENV=production /path/to/application/dir/bin/delayed_job restart` – Ashik Salman Feb 27 '18 at 06:52
  • Thank you for your response. But am I not doing it already? In the first line, I switch to the current directory, on the fourth I restart DJ. – mohnstrudel Feb 28 '18 at 09:11
  • 1
    My mistake. Anyway it has nothing to do with cron job. It seems like issue with environment settings/gem loading reference. Did you check [this answer](https://stackoverflow.com/questions/38663706/loaderror-could-not-load-the-listen-gem-rails-5), might help . – Ashik Salman Feb 28 '18 at 09:47
  • Great help, thank you! The 'bad' workaround, using `gem 'listen', '~> 3.1.5'` helped me indeed. – mohnstrudel Mar 02 '18 at 08:42
  • Welcome, Glad to hear that you got it working. – Ashik Salman Mar 02 '18 at 09:34

0 Answers0