NameError using Rails, Sidekiq & Clockwork

453 views Asked by At

Looking at the 'Example clock.rb file' here in the documentation, you can see that my code follows the clockwork conventions (?) exactly. 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:

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".

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:

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

There are 1 answers

0
Ed Halferty On BEST ANSWER

Take a look at the Clockwork gem module structure. 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

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

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.