Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails, using whenever gem in development

Sorry quick question here from a relative Rails newbie. I'm trying to use the Whenever gem to schedule a number of rake tasks. I can't for the life of me get it to actually begin running the cron jobs on my development machine.

Judging from other stackoverflow threads, it appears I should add this:

set :environment, "development" 

to my schedule.rb file. But then what?

And then how do I stop the cron jobs once they've started?

Using Rails 3.2.3 in OSX

UPDATE: the answer is to run $ whenever -w which writes the cron job to a crontab file. The system then immediately starts running that crontab file automatically.

Unfortunately, my logfile for whenever contains the following: "rake aborted! Don't know how to build task <task name>"

I'm thinking this might be due to the known crontab/rvm issue, but any suggestions are welcome.

like image 692
user1377556 Avatar asked Jul 17 '12 01:07

user1377556


People also ask

What is whenever gem?

Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs.


2 Answers

Clear existing cron jobs.

crontab -r 

Update cronjob with the environment.

whenever --update-crontab --set environment='development' 
like image 70
Ashwin Yaprala Avatar answered Sep 21 '22 01:09

Ashwin Yaprala


You can use the whenever command and its various options to manipulate your crontab.

$ whenever --help Usage: whenever [options]     -i [identifier],                 Default: full path to schedule.rb file         --update-crontab     -w, --write-crontab [identifier] Default: full path to schedule.rb file     -c, --clear-crontab [identifier]     -s, --set [variables]            Example: --set 'environment=staging&path=/my/sweet/path'     -f, --load-file [schedule file]  Default: config/schedule.rb     -u, --user [user]                Default: current user     -k, --cut [lines]                Cut lines from the top of the cronfile     -v, --version 
like image 26
Conner Avatar answered Sep 17 '22 01:09

Conner