简体   繁体   English

如何使用Clockwork运行Helper / Controller方法?

[英]How do you run a Helper / Controller method using Clockwork?

I'm sure I've got the completely wrong of the stick with regard to how Clockwork works. 关于发条的工作原理,我确定我完全犯了错误。 Basically I'm got a number of methods that exist within a Controller, as they're currently triggered by navigating to their relevant routes. 基本上,Controller中存在许多方法,因为它们当前是通过导航到它们的相关路径来触发的。 I'm trying to get clockwork to run these methods, but I get a number of errors, including No Method Errors. 我正在尝试使这些方法运行,但出现了许多错误,包括“无方法错误”。

I've had a look around but can't seem to find anything to point me in the right direction. 我环顾四周,但似乎找不到任何指向我正确方向的东西。 If this isn't the way to do it, where do I need to put my action logic in order to execute it using Clockwork? 如果这不是做到这一点的方法,那么我需要将动作逻辑放在哪里才能使用Clockwork执行它?

This is my clock.rb file at the moment, which results in a NoMethodError 这是我当前的clock.rb文件,导致NoMethodError

require 'clockwork'
require './config/boot'
require './config/environment'

include Clockwork

handler do |job|
  puts "Running #{job}"
end

every(3.minutes, 'application.tester') { ApplicationController::tester }

This is horrible OO practice, let Rails call controller methods. 这是很糟糕的OO实践,让Rails调用控制器方法。 Whatever code you have in these controller methods move to its own class or module and call them in a Rake task. 这些控制器方法中包含的所有代码都将移至其自己的类或模块,并在Rake任务中调用它们。 Then proceed to call that rake task in Clockwork. 然后继续在Clockwork中调用该rake任务。

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

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