2

in my config/schedule.rb:

set :environment, "development"
set :output, "log/cron.log"

every 2.minutes do
  rake "reset_expired_pin:generate"
end

then i run whenever --update-crontab --set environment='development' then crontab -l i see the cron in that list and after I refresh my DB every 2 mins, it doesn't update anything ( my rake command not run ), I have a search on this issue on this StackOverflow and do what the answers said, but doesn't work so i finally ask here to get help, is wheneever gem not support on OSX ? and can't be running in development mode ?? i also can't found the log file of that cron , i thought it gonna saved in my rails app root, but it doesn't, i follow this intructions to get log, and i follow this instructions for run whenever but nothing lucking to find this log in my Mac

crontab -l:


# Begin Whenever generated tasks for: /Users/me/Documents/myapp/config/schedule.rb at: 2020-05-16 07:12:15 +0800
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 
'export PATH="$HOME/.rbenv/bin:$PATH"; eval "$(rbenv init -)"; cd /Users/me/Documents/myapp && RAILS_ENV=development bundle exec rake reset_expired_pin:generate --silent >> log/cron.log 2>&1'

# End Whenever generated tasks for: /Users/me/Documents/myapp/config/schedule.rb at: 2020-05-16 07:12:15 +0800
certual
  • 87
  • 9
  • Plenty of things could be wrong. Check to make sure your cron daemon is running? Can it run regular jobs like `echo test > /tmp/test`? If not, then your cron daemon isn't working. If it does work, then look for your cron daemon logs (nothing to do with ruby or gem). – Stephen Crosby May 15 '20 at 23:23
  • Can you show the resulting `crontab` that was generated? – tadman May 15 '20 at 23:29
  • @StephenCrosby how to check it – certual May 15 '20 at 23:34
  • @tadman just updated the log of it above – certual May 15 '20 at 23:34
  • That indicates where the log should be. What's in it? Do you have a `/Users/me/Documents/myapp/log` directory? – tadman May 15 '20 at 23:35
  • ohh yes it is there, but i got error: `/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/bundler_version_finder.rb:80:in `pwd': Operation not permitted - getcwd (Errno::EPERM)` , i think i am using 2.7.1 by rbenv , but i dont know why they use 2.6 – certual May 15 '20 at 23:40
  • also it said ~/myapp/.ruby-version: Operation not permitted @tadman – certual May 15 '20 at 23:41
  • That's a permission problem of some kind. Looks like rbenv isn't loading in your cron environment. – tadman May 15 '20 at 23:44
  • i saw whenever wiki said i should put this `set :rbenv_root, '/opt/rbenv'` but when i search /opt/rbenv on my local , not found, how to know the root rbenv ?? @tadman – certual May 15 '20 at 23:50
  • i found it by called ''~/.rbenv" but still got that error ~/myapp/.ruby-version: Operation not permitted @tadman – certual May 16 '20 at 00:02
  • just found out it @tadman – certual May 16 '20 at 00:14

1 Answers1

4

i found it just now, been find out this problem since yesterday and found out just now, to resolve it, we should set up the env of RBENV if you are using RBENV and set the version of ruby and it gonna find the ruby-version in your root file app rail i set it up it

set :rbenv_root, '~/.rbenv'
set :rbenv_version, '2.7.1'
env 'RBENV_ROOT', rbenv_root
env 'RBENV_VERSION', rbenv_version
job_type :rake, 'export PATH="$HOME/.rbenv/bin:$PATH"; eval "$(rbenv init -)"; cd :path && :environment_variable=:environment bundle exec rake :task --silent :output'
set :environment, "development"

env of RBENV must on the top and on that job_type: we set it up for get the PATH of rbenv because it gonna run by bash

one thing is more importan the ~/Libary on Mac must be executable, so we could it set up for cron follow this : https://blog.bejarano.io/fixing-cron-jobs-in-mojave/

certual
  • 87
  • 9
  • `job_type :rake, 'export PATH="$HOME/.rbenv/bin:$PATH"; eval "$(rbenv init -)"; cd :path && :environment_variable=:environment bundle exec rake :task --silent :output'` made my day! – Lane Sep 07 '21 at 00:50