【问题标题】:Rails: Cron jobs with whenever gemRails:使用每当 gem 的 Cron 作业
【发布时间】:2016-03-01 13:26:44
【问题描述】:

我是 cron 工作和 rails 的新手。我已经安装了whenever gem。现在我想从tmp/cache/foo.txt删除一个文件。

schedule.rb

every 5.minutes do
    command "rm '#{path}/tmp/cache/foo.txt' "
end

当我运行whenever 命令时,它说:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'rm '\''/home/techbirds/shivam/tmp/cache/foo.txt'\'''

## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options

那么如何从头开始呢?

【问题讨论】:

  • whenever --update-crontab更新你的crontab

标签: ruby-on-rails ruby cron cron-task whenever


【解决方案1】:

您应该根据新的schedule.rb 规则更新crontab定义命令以按所需计划定期运行的配置文件),因此您应该运行以下命令(如果此作业设置为您的schedule.rb 中的特定环境,您还应该--set 环境):

whenever --update-crontab

要查看您当前的作业,请使用 crontab -ewhenever 生成的作业将包含在 # Begin Whenever# End Whenever 块中)。

【讨论】:

  • 好的,我已经使用了该命令,但文件仍然没有删除
  • @AniketShivamTiwari:有点模糊,到底是什么不工作?您在crontab 中有正确的规则吗?当您从终端运行命令时会发生什么?您的路径是否正确?
  • whenever --update-crontab --set environment='staging' 这对我有用,用于更改环境
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-05
相关资源
最近更新 更多