Whenever: Whenever 0.9.4 generating runner commands with script/runner, which does not exist in Rails 4

Created on 17 Sep 2015  ·  7Comments  ·  Source: javan/whenever

I am using rails 4.2.3 with whenever 0.9.4 and capistrano 3.1. Everything related to scheduling cron jobs works fine except that I get periodic errors in my cron.log (in production) with the following content:

/bin/bash: script/runner: No such file or directory

then in my crontab -l I have the following:

/bin/bash -l -c 'cd /home/deploy/delight/releases/20150916202925 && script/runner -e production '\''Liab.move_expired'\'' >> /home/deploy/delight/releases/20150916202925/log/cron.log 2>&1'

which curiously uses the "script/runner" command, which is no longer available in Rails 4 according to this topic on stackoverflow:

http://stackoverflow.com/questions/19683405/why-is-rails-runner-e-production-not-working

furthermore, I have included the require 'capistrano/bundler' in my Capfile, and I expect the generated the cron command to contain something like this:

bundle exec rails runner -e production

instead of

script/runner -e production

currently I am thinking about creating a custom job_type that manually generates the required rails runner command, but I think this is an issue worth resolving.

bugfix

Most helpful comment

I worked around this by adding a custom runner to the schedule.rb file:

job_type :custom_runner,  
  "cd :path && bundle exec rails runner -e :environment ':task' :output"

every 5.minutes do
  custom_runner "Liab.move_expired"
end

but I am still wondering why would whenever generate the deprecated script/runner command on a rails 4 project?

All 7 comments

I worked around this by adding a custom runner to the schedule.rb file:

job_type :custom_runner,  
  "cd :path && bundle exec rails runner -e :environment ':task' :output"

every 5.minutes do
  custom_runner "Liab.move_expired"
end

but I am still wondering why would whenever generate the deprecated script/runner command on a rails 4 project?

Yeah, I had the same problem,

I assume you are running that command on your server, inside your current production directory. And you are using Capistrano 3 for deployment.

In that case, go to your deploy.rb file and remove the bin directory from the linked_dirs option. Now re-deploy your app.

For some reason, capistrano 3 contributors decided to share the bin directory among all deployments by default. The bin directory is also always empty and I cannot imagine why. As a result, when you try to run anything inside the rails environment on your server, such as rails console or rails runner it does not recognize the rails app and says you need to make a new rails app.

remove bin from linked_dirs and suddenly you can run the rails runner command.

Also I have found that after each deployment, you need to first edit your crontab and remove the entry for the previous release and then run bundle exec whenever --update-crontab in your current release directory for the gem to work properly.

Awesome!
Sorry I removed the question because I thought that it may be me using wrong capistrano (which was true xD). But now I believe that it may help others.
In my case rails runner command was not working and it throws me the rails usage output.

Thanks @alitivay !! Now my emails work perfectly.

PD: just with removing the bin directory from the Capfile then the crontab start working perfectly without the job_type work arround. Here are my gem versions:

[email protected]
[email protected]

Excellent !

I didn't know why my cronjob wasn't work... But thank you guys, i was scared hahah... Thank you for the great helo. 👍

@alitivay You're a champ 🥳

Was this page helpful?
0 / 5 - 0 ratings