1

查看文档中的“示例clock.rb文件” ,您可以看到我的代码完全遵循发条约定(?)。但是,我收到了这个似乎无法修复的错误。我尝试过对不同的变量进行复数和单数化。

`<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

本质上,我希望 Clockwork 将(1)循环遍历每个model_instance 如上所示,(2)通过数据库关联找到frequency_quantityand frequency_period(它们一起构成“时间”),以及(3)调用TwilioWorker右侧的“时间”。

我试过用下面的代码替换块。当我运行时clock.rb,我可以接到来自 Twilio 的电话:

every(1.minutes, "twilio_call.job") { TwilioWorker.perform_async }
4

1 回答 1

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 模块中的不同类。

于 2014-12-02T18:50:55.100 回答