0

I'm trying to run an Sidekiq example in Crystal, but I've got an error in Sidekiq log:

2016-11-03T13:18:22.430Z 19329 TID-uvtuk WARN: {"queue"=>"default", "jid"=>"84853f6ac0bf8d434ec0beee", "class"=>"Sample::MyWorker", "args"=>["world", 3], "created_at"=>1478179102.4277496, "enqueued_at"=>1478179102.4281816, "retry"=>true}
2016-11-03T13:18:22.430Z 19329 TID-uvtuk WARN: NameError: uninitialized constant Sample

ok_photos>src>ok_photos>workers.cr

require "sidekiq"
module Sample
  class MyWorker
    include Sidekiq::Worker

    def perform(name : String, count : Int64)
      count.times do
        logger.info "hello, #{name}!"
      end
    end
  end
end

ok_photos>src>ok_photos.cr

require "./ok_photos/*"
require "sidekiq"

Sidekiq::Client.default_context = Sidekiq::Client::Context.new

Sample::MyWorker.async.perform("world", 3_i64)

What I'm doing wrong?

nobilik
  • 736
  • 9
  • 29
  • 1
    It may be a problem with namespacing. Can you try without the namespace? – Serdar Dogruyol Nov 03 '16 at 14:00
  • @SerdarDogruyol Thanks, your comment was very useful. There is a problem with namespaces. If you want see my comment under Mike's answer. I really can't understand why... – nobilik Nov 04 '16 at 01:23

1 Answers1

2

You are showing the client code but not the server code. The server isn't requiring your Sample namespace so it doesn't know how to execute the job.

Mike Perham
  • 21,300
  • 6
  • 59
  • 61
  • Thank you Mike. I stupidly decide that my Sidekiq gem installed in Rails can proceed this job. Now everything is working fine. But, I don't know why, there is a problem with namespaces. `require "./src/sample"` doesn't work, but `require "./sample/workers"` works fine. Same thing with my project code: requiring `"./ok_photos/*"` and `"./ok_photos/**"` gives me error `uninitialised constant Sample`, but with `require "./sample/workers"` it runs. – nobilik Nov 04 '16 at 01:20