查看'示例clock.rb
文件'文档中的here,您可以看到我的代码完全符合发条约定(?)。但是,我收到的这个错误似乎无法解决。我试过多元化和单一化不同的变量。
`<module:Clockwork>': uninitialized constant Clockwork::Event::Manager (NameError)
from /Users/MightyMouse/Desktop/DevBootcamp/phase-3/medmento/config/clock.rb:7:in `<top (required)>'
from /Users/MightyMouse/.rvm/gems/ruby-2.0.0-p598/gems/clockwork-1.1.0/bin/clockwork:12:in `require'
from /Users/MightyMouse/.rvm/gems/ruby-2.0.0-p598/gems/clockwork-1.1.0/bin/clockwork:12:in `<top (required)>'
from /Users/MightyMouse/.rvm/gems/ruby-2.0.0-p598/bin/clockwork:23:in `load'
from /Users/MightyMouse/.rvm/gems/ruby-2.0.0-p598/bin/clockwork:23:in `<main>'
from /Users/MightyMouse/.rvm/gems/ruby-2.0.0-p598/bin/ruby_executable_hooks:15:in `eval'
from /Users/MightyMouse/.rvm/gems/ruby-2.0.0-p598/bin/ruby_executable_hooks:15:in `<main>'
这是我的clock.rb
文件:
require_relative "../config/boot"
require_relative "../config/environment"
require 'clockwork'
require 'clockwork/database_events'
module Clockwork
Clockwork.manager = Event::Manager.new
sync_database_events model: ClockworkEvent, every: 1.minute do |model_instance|
TwilioWorker.perform_async
end
end
基本上,我希望发条将(1)循环遍历每个model_instance
,如上所示,(2)找到frequency_quantity
和{{1 (通过数据库关联,它们一起组成&#34; time&#34;);(3)在右边&#34;时间&#34;调用frequency_period
。
我尝试用下面的代码替换该块。当我运行TwilioWorker
时,我可以接到Twilio的电话:
clock.rb
答案 0 :(得分:1)
看看Clockwork gem模块结构。如果您尝试引用此文件:https://github.com/tomykaira/clockwork/blob/master/lib/clockwork/manager.rb 然后你需要使用
Clockwork.manager = Manager.new
(可能已经是默认值)
而不是
Clockwork.manager = Event::Manager.new
因为Manager类直接位于Clockwork模块内(您可能以
开头) Clockwork.manager = DatabaseEvents::Manager.new
这是一个不同的情况,因为Manager引用了Clockwork模块内DatabaseEvents模块中的另一个类。