Reputation: 961
I wanted to set a cron tab which would execute a task located in my Rails app. In my config/schedule.rb:
every 2.minutes do
#do something
end
Despite putting this task successfully into my cron jobs list it never gets executed. When I try to manually launch the script saved in my cron jobs list, that is:
/bin/bash -l -c 'cd /Users/me/Desktop/railsapp && RAILS_ENV=production bundle exec rake reports:fetch --silent'
I get error about wrong Ruby version:
Your Ruby version is 2.6.3, but your Gemfile specified 2.6.6
I use rbenv and both my local and global versions are set to 2.6.6. Furthermore version 2.6.3 is not even present on the list of available ones.
How can I change this version to proper one and make my cron jobs executable?
Upvotes: 2
Views: 802
Reputation: 219
I am getting same errors on Pro M1.
My app ruby version is 3.1.2, default MAC system verison is 2.6.8
I have add to ~/.bash_profile
file this content:
export RBENV_ROOT="${HOME}/.rbenv"
if [ -d "${RBENV_ROOT}" ]; then
export PATH="${RBENV_ROOT}/bin:${PATH}"
eval "$(rbenv init -)"
fi
And then run . ~/.bash_profile
.
Add this line to schedule.rb
: env :PATH, ENV["PATH"]
=> Don't forget update crontab with: whenever --update-crontab --set environment='development'
Crontab is working with rbenv.
Refs: https://blog.eq8.eu/article/cronntab-rbenv-bundle-exec-rake-task.html
Upvotes: 2