简体   繁体   English

Rails发条没有运行代码

[英]Rails clockwork not running code

I'm using the gem 'clockwork' in a Rails 3.2 app. 我在Rails 3.2应用程序中使用gem'clockwork'。 The app is running on Heroku. 该应用程序在Heroku上运行。 The clock job runs at 1am - but it's not executing the code. 时钟作业在凌晨1点运行 - 但它没有执行代码。

Here is the clock.rb code: 这是clock.rb代码:

  Clockwork.every(1.day, 'DailyJob', :at => '01:00'){
    StatsMailer.stats_email.deliver
    Forecast.where(:run_date => Date.today).each  do |forecast|
      woschedules_run_jobplans_path(:id => forecast.woschedule_id)
    end
  }

The log shows: 日志显示:

Sep 04 00:00:05 ndeavor-staging app/clock.1: #<NoMethodError: undefined method `woschedules_run_jobplans_path' for Clockwork:Module> 9月04日00:00:05 ndeavor-staging app / clock.1:#<NoMethodError:未定义的方法`woschedules_run_jobplans_path'用于发条:模块>

If I rake routes, I get: 如果我耙路线,我得到:

woschedules_run_jobplans GET   /woschedules/run_jobplans(.:format) woschedules#run_jobplans

The error is in that the route is non-existant. 错误在于路线不存在。 Since the route DOES exist, this problem usually means that the Rails routes have not been loaded into the current scope. 由于路径存在,这个问题通常意味着Rails路由尚未加载到当前范围。

You may need to include Rails' route helpers in order for it to function properly: Rails.application.routes.url_helpers 您可能需要包含Rails的路由助手才能使其正常运行: Rails.application.routes.url_helpers

Clockwork.every(1.day, 'DailyJob', :at => '01:00'){
  StatsMailer.stats_email.deliver
  Forecast.where(:run_date => Date.today).each  do |forecast|
    # Prepend your route with the following:
    Rails.application.routes.url_helpers.woschedules_run_jobplans_path(:id => forecast.woschedule_id)
  end
}

Alternatively, to dry it up a bit you can simply include all of the route helpers at the beginning of the file using: 或者,要稍微干一点,您可以使用以下命令在文件开头简单地包含所有路径助手:

# Beginning of file
include Rails.application.routes.url_helpers

# ...

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

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