I'm trying to create a cron job that runs a controller method with the whenever gem but i'm having trouble. I'm getting
bundler: not executable: bin/rails
in my cron.log file.
schedule.rb
every 1.minutes do
runner "Reset.reset"
end
reset.rb
class Reset < ActiveRecord::Base
def self.reset
logger.debug("This is the cron job")
end
end
I also ran the whenever --update-crontab to update the cron job.
Why isn't the logger message showing up in the log?
Thanks for all the help.
Out put of crontab -l
sm start rvm
sm end rvm
Begin Whenever generated tasks for: /home/john/rails_app/config/schedule.rb PATH=/home/john/bin:/home/john/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/john/.rvm/bin
GEM_PATH=""
***** /bin/bash -l -c 'cd /home/john/rails_app && bundle exec bin/rails runner -e development '\''Reset.reset_payments'\'' >>/home/john/rails_app/log/cron.log 2>>/home/john/rails_app/log/error.log'
End Whenever generated tasks for: /home/john/rails_app/config/schedule.rb
The documentation states that for runner, the command looks like: cd :path && bin/rails runner -e :environment ':task' :output
. But in your crontab it looks like: ...bundle exec bin/rails runner -e development...
Run crontab -e
and delete bundle exec manually or specify job_type :runner
in your schedule.rb
file, as in the documentation. For me, this solved the problem.
job_type :runner, "cd :path && bin/rails runner -e :environment ':task' :output"
every 1.minutes do
runner "Reset.reset"
end