繁体   English   中英

每当gem时,Cron工作都不起作用

[英]Cron job doesn't work with whenever gem

我想创建一个计划cron作业。 我曾经用过。 我的rails版本是4.1.6,我在osx中​​。

因此,我创建了一个计划cron作业进行测试。

schedule.rb

every 1.minutes do
    runner "DatabaseWatcher.run"
end

补丁:

/lib/DatabaseWatcher.rb

类:

class DatabaseWatcher
        def run
            puts "test"
        end
     end

在此之后,我做了:

$每当

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

$每当-w

[write] crontab file written

我从未在命令行中看到过“测试”。 我做错了什么?

我之前已经有此错误。 使用.self在运行方法中添加类方法。 如果未调用/lib/DatabaseWatcher.rb DatabaseWatcher, /lib/DatabaseWatcher.rb必须移至文件夹app / models / database_watcher.rb

class DatabaseWatcher
  def self.run
    puts "test"
  end
end

这是为了在环境开发中更新您的crontab。

# to update crontab
whenever --update-crontab --set environment=development
# show crontab list
crontab -l

供参考:

  1. Rails的使用,只要宝石参与发展

暂无
暂无

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

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