2

I am using RVM environment. RUby version : 2.1.2 rails : 4.1.1

schedule.rb : 

    every 1.minute do 
    runner "note.send_mail" 
    end 

I used whenever --update-crontab to update the cron tab.

when I check the jobs using crontab -l it shows up as below with no proper time set up. and the cron job does not work.

 * * * * * /bin/bash -l -c 'cd /Desktop/folder1/blog2 && bin/rails runner -e production '\''note.send_mail'\''' 

Can some one help me out fix this. Thanks!

user2569524
  • 1,651
  • 7
  • 32
  • 57
  • 1
    crontab time format is `minutes hours day_of_month month day_of_week` so every 1.minute really should result to `* * * * *` as it did for you. Every 2.minutes will be `*/2 * * * *` and every 1.hour would be `0 * * * *` ("any time when minutes is 0"). Every 6.hours would be `0 */6 * * *` – Kimmo Lehto Jun 07 '14 at 15:10
  • 1
    the runner probably doesn't work, i guess that should be `runner "Note.send_mail"` or something like that instead. – Kimmo Lehto Jun 07 '14 at 15:17

2 Answers2

2

Go to your ~/.rvmrc file and add the following:

rvm_trust_rvmrcs_flag=1

Then whenever --update-crontab again. According to the README of whenever:

If your production environment uses RVM (Ruby Version Manager) you will run into a gotcha that causes your cron jobs to hang. This is not directly related to Whenever, and can be tricky to debug. Your .rvmrc files must be trusted or else the cron jobs will hang waiting for the file to be trusted. A solution is to disable the prompt by adding this line to your user rvm file in ~/.rvmrc

rvm_trust_rvmrcs_flag=1

This tells rvm to trust all rvmrc files.

If that doesn't work for you, try other solutions mentioned in this page: RVM-Notes.

Community
  • 1
  • 1
Tamer Shlash
  • 9,314
  • 5
  • 44
  • 82
  • I cant see the .rvmrc file anywhere ... where is it usually. All I see is etc/rvmrc file . I have added that entry there. But does not work as well – user2569524 Jun 07 '14 at 02:15
  • @user2569524 Assuming you're on a Linux distro, the `.rvmrc` file should be in your user home folder. If there's not such a file, create one. However, make sure it doesn't exist as files whose name begin with a dot (`.`) are hidden on Linux. – Tamer Shlash Jun 07 '14 at 02:36
  • how would that file change the fact that the cron job is not loading rvm environment? – Sofia Bravo Nov 12 '15 at 21:57
  • For me there was no `.rvmrc` file, but it was easy enough to create, and worked perfectly after that. – maurice Dec 27 '16 at 17:58
0

You could define a custom runner that loads rvm on the command line, like

job_type :runner_with_rvm, 'source /etc/profile.d/rvm.sh; cd :path;rvm 2.0@gemset do bundle exec script/rails runner -e :environment ':task' :output'

every 1.minute do
  runner_with_rvm "Note.send_email"
end

Replace 2.0@gemset with your desired ruby version and gemset.

Could be that /etc/profile.d/rvm.sh is something else in your environment too.

Kimmo Lehto
  • 5,910
  • 1
  • 23
  • 32
  • there seems to be a syntax error on the runner_with_rvm definition: ```/home/user/.rvm/gems/ruby-2.2.2@big/gems/whenever-0.9.4/lib/whenever/job_list.rb:25:in `instance_eval': config/schedule.rb:1: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' (SyntaxError) ... runner -e :environment ':task' :output' ...``` – Sofia Bravo Nov 12 '15 at 21:43
  • The issue is that he's not ecaping the quotes around 'task' change to \':task\' – Joshua Tyree Jun 15 '21 at 19:32