如何将我的随便任务安装为cron作业?

时间:2017-07-31 16:37:09

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

我正在使用Rails 5.我想定期运行一个任务,所以我正在阅读“随时”宝石。安装后,我用

创建了文件./config/schedule.rb
# Learn more: http://github.com/javan/whenever
set :environment, "development"

every 10.minutes
  rake "events:calc_index"
end

不幸的是,当我尝试使用“when --crontab”在我的系统中安装它时,正如我所知道的那样,我得到了这个错误

localhost:cindex davea$ whenever --update-crontab
/Users/davea/.rvm/gems/ruby-2.4.0/gems/whenever-0.9.7/lib/whenever/job_list.rb:25:in `instance_eval': config/schedule.rb:25: syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError)
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/whenever-0.9.7/lib/whenever/job_list.rb:25:in `initialize'
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/whenever-0.9.7/lib/whenever.rb:12:in `new'
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/whenever-0.9.7/lib/whenever.rb:12:in `cron'
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/whenever-0.9.7/lib/whenever/command_line.rb:54:in `whenever_cron'
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/whenever-0.9.7/lib/whenever/command_line.rb:107:in `updated_crontab'
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/whenever-0.9.7/lib/whenever/command_line.rb:35:in `run'
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/whenever-0.9.7/lib/whenever/command_line.rb:6:in `execute'
    from /Users/davea/.rvm/gems/ruby-2.4.0/gems/whenever-0.9.7/bin/whenever:41:in `<top (required)>'
    from /Users/davea/.rvm/gems/ruby-2.4.0/bin/whenever:22:in `load'
    from /Users/davea/.rvm/gems/ruby-2.4.0/bin/whenever:22:in `<main>'
    from /Users/davea/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/davea/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'

什么时候安装我的cron作业?

1 个答案:

答案 0 :(得分:0)

快速查看文档,您似乎需要这样做:every 10.minutes do,而不是every 10.minutes