简体   繁体   English

使用Rails,Sidekiq和发条的NameError

[英]NameError using Rails, Sidekiq & Clockwork

Looking at the 'Example clock.rb file' here in the documentation, you can see that my code follows the clockwork conventions (?) exactly. 望着“例子clock.rb文件” 这里的文档中,你可以看到,我的代码如下发条公约(?)完全相同。 However, I'm getting this error that I can't seem to fix. 但是,我收到了似乎无法修复的错误。 I've tried pluralizing and singularizing different variables. 我尝试过对不同的变量进行复数和单数化处理。

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

Here's my clock.rb file: 这是我的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

Essentially, I'm hoping that Clockwork will (1) loop through each model_instance as seen above , (2) find the frequency_quantity and frequency_period (together, they make up the "time") through the database associations, and (3) invoke the TwilioWorker at the right "time". 从本质上讲,我希望发条会(1)通过每个回路model_instance 如上面看到的 ,(2)找到frequency_quantityfrequency_period通过数据库协会(一起,他们组成了“时间”),以及(3)调用TwilioWorker在正确的“时间”。

I've tried replacing the block with the code below. 我尝试用下面的代码替换该块。 When I run the clock.rb , I am able to get a phone call from Twilio: 运行clock.rb ,我可以从Twilio接到电话:

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

Take a look at the Clockwork gem module structure. 看一下Clockwork gem模块的结构。 If you're trying to reference this file: https://github.com/tomykaira/clockwork/blob/master/lib/clockwork/manager.rb then you'll need to use 如果您尝试引用此文件: https : //github.com/tomykaira/clockwork/blob/master/lib/clockwork/manager.rb,则需要使用

Clockwork.manager = Manager.new

(probably already the default) (可能已经是默认值)

instead of 代替

Clockwork.manager = Event::Manager.new

because the Manager class is directly inside the Clockwork module (you probably started with 因为Manager类直接位于Clockwork模块内部(您可能从

Clockwork.manager = DatabaseEvents::Manager.new

which is a different case because Manager refers to a different class inside the DatabaseEvents module inside the Clockwork module. 这是不同的情况,因为Manager在Clockwork模块内的DatabaseEvents模块内引用了不同的类。

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

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