简体   繁体   English

Rails,在开发中使用gem时使用

[英]Rails, using whenever gem in development

Sorry quick question here from a relative Rails newbie. 对不起快速问题来自相关的Rails新手。 I'm trying to use the Whenever gem to schedule a number of rake tasks. 我正在尝试使用Whenever gem来安排一些rake任务。 I can't for the life of me get it to actually begin running the cron jobs on my development machine. 我不能为我的生活让它真正开始在我的开发机器上运行cron作业。

Judging from other stackoverflow threads, it appears I should add this: 从其他stackoverflow线程来看,似乎我应该添加:

set :environment, "development"

to my schedule.rb file. 到我的schedule.rb文件。 But then what? 但那又怎样?

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. 更新:答案是运行$ whenever -w将cron作业写入crontab文件。 The system then immediately starts running that crontab file automatically. 然后系统立即开始自动运行该crontab文件。

Unfortunately, my logfile for whenever contains the following: "rake aborted! Don't know how to build task <task name>" 不幸的是,我的日志文件只包含以下内容: "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. 我想这可能是由于已知的crontab / rvm问题,但欢迎任何建议。

Clear existing cron jobs. 清除现有的cron作业。

crontab -r

Update cronjob with the environment. 用环境更新cronjob。

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

You can use the whenever command and its various options to manipulate your crontab. 您可以使用whenever命令及其各种选项来操作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
whenever -c cron-name  #removing cronjobs 

在config / schedule.rb之上添加以下代码行为我工作。

 ENV['RAILS_ENV'] = "development"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM