Rails,开发时使用gem

时间:2022-12-01 08:02:03

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.

不好意思,这是一个Rails新手的问题。我正在尝试使用“随时gem”来安排一些rake任务。我不可能让它开始在我的开发机器上运行cron作业。

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

从其他*线程来看,我似乎应该添加以下内容:

set :environment, "development"

to my schedule.rb file. But then what?

我的日程安排。rb文件。但然后呢?

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

那么,一旦cron的工作开始了,我该如何阻止呢?

Using Rails 3.2.3 in OSX

在OSX中使用Rails 3.2.3

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.

更新:答案是每当-w将cron作业写入crontab文件时运行$。然后系统立即自动开始运行crontab文件。

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

不幸的是,无论何时,我的日志文件都包含以下内容:“rake aborted!”不知道如何构建task "

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

我认为这可能是由于已知的crontab/rvm问题,但是任何建议都是受欢迎的。

4 个解决方案

#1


57  

Clear existing cron jobs.

明确现有的cron作业。

crontab -r

Update cronjob with the environment.

使用环境更新cronjob。

whenever --update-crontab --set environment='development'

#2


6  

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

您可以使用随时命令及其各种选项来操作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

#3


2  

whenever -c cron-name  #removing cronjobs 

#4


0  

Adding following line of code on top of config/schedule.rb worked for me.

在配置/计划顶部添加以下代码行。rb为我工作。

 ENV['RAILS_ENV'] = "development"

#1


57  

Clear existing cron jobs.

明确现有的cron作业。

crontab -r

Update cronjob with the environment.

使用环境更新cronjob。

whenever --update-crontab --set environment='development'

#2


6  

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

您可以使用随时命令及其各种选项来操作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

#3


2  

whenever -c cron-name  #removing cronjobs 

#4


0  

Adding following line of code on top of config/schedule.rb worked for me.

在配置/计划顶部添加以下代码行。rb为我工作。

 ENV['RAILS_ENV'] = "development"