0

I'm trying to implement Sneakers, but I'm having some issues. Below you can find the code which subscribers to my queue and the actual error.

require 'sneakers'
require 'jwt'
require 'redis'
require 'json'


$redis = Redis.new(url: ENV['REDIS_URL'], password: ENV['REDIS_PASSWORD'])

class Processor
  include Sneakers::Worker
  QUEUE_NAME = :my_queue

  from_queue QUEUE_NAME

  def work(msg)
    message = JSON.parse(msg)
    if message["type"] == "error"
      $redis.incr "processor:#{err["error"]}"
    end

    controller = Object.const_get message['controller']
    action = message['method']
    controller.public_send(action, message['msg'])

    ack!
  end
end

Error:

[Exception error="uninitialized constant V1" error_class=NameError worker_class=Processor

The msg object

{\"controller\":\"V1::x::yController\",\"method\":\"my_method"\}

Any help is welcome, thank you!

Update

Even getting a simple Model such as my User is resulting into the same error.

[Exception error="uninitialized constant User"

I'm running the sneakers worker like so:

sneakers work UserCreate --require app/workers/user_create.rb
testbuck
  • 21
  • 2
  • 1
    If you're using it with rails you should probably follow this wiki: https://github.com/jondot/sneakers/wiki/How-To%3A-Rails-Background-Jobs The failures you're getting seem to be because your dependencies are not loaded/required by the time sneakers tries to reach them. – fabriciofreitag Oct 12 '20 at 14:41
  • @fabriciofreitag Thanks for your response. I did follow that wiki indeed. I've also prefixed all the initializers to make sure that the `sneakers.rb` initializer is the last one to run. This now results in something interesting. It's unable to find simple has_one, has_many etc relationships. `NoMethodError: undefined method `has_one'`. – testbuck Oct 12 '20 at 16:39
  • You'll have to provide more context, the rest of your code, how are you calling it, etc. Update your question with everything you currently have, it's difficult to guess as it is, try to put yourself in the shoes for other people reading the question, as if they didn't have access to your code. Thanks. – fabriciofreitag Oct 12 '20 at 18:28

0 Answers0