Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: uninitialized constant UniqueTextWorker #1043

Closed
kshnurov opened this issue Jul 4, 2013 · 23 comments
Closed

NameError: uninitialized constant UniqueTextWorker #1043

kshnurov opened this issue Jul 4, 2013 · 23 comments

Comments

@kshnurov
Copy link

kshnurov commented Jul 4, 2013

I have a typical worker:

class UniqueTextWorker
  include Sidekiq::Worker
  sidekiq_options :queue => :background

  def perform(place_id)
...

When I'm trying to run some workers (seriosly - some place_ids work, some not), I'm getting an error: "NameError: uninitialized constant UniqueTextWorker".
Code is totally fine and successfully working outside of sidekiq. Backtrace is useless. What's wrong?

activesupport-3.2.11/lib/active_support/inflector/methods.rb:230→ block in constantize
activesupport-3.2.11/lib/active_support/inflector/methods.rb:229→ each
activesupport-3.2.11/lib/active_support/inflector/methods.rb:229→ constantize
activesupport-3.2.11/lib/active_support/core_ext/string/inflections.rb:54→ constantize
sidekiq-2.12.0/lib/sidekiq/processor.rb:43→ process
celluloid-0.14.0/lib/celluloid/calls.rb:25→ public_send
celluloid-0.14.0/lib/celluloid/calls.rb:25→ dispatch
celluloid-0.14.0/lib/celluloid/calls.rb:125→ dispatch
celluloid-0.14.0/lib/celluloid/actor.rb:328→ block in handle_message
celluloid-0.14.0/lib/celluloid/tasks.rb:42→ block in initialize
celluloid-0.14.0/lib/celluloid/tasks/task_thread.rb:20→ block in create
celluloid-0.14.0/lib/celluloid/internal_pool.rb:59→ call
celluloid-0.14.0/lib/celluloid/internal_pool.rb:59→ block in create
@darkside
Copy link

darkside commented Jul 4, 2013

Assuming you're using Rails, this could be related to autoload, I've seen this happen. Is your worker sitting under lib/ ?

@kshnurov
Copy link
Author

kshnurov commented Jul 4, 2013

No, it's in app/workers and here's config:

config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]
config.eager_load_paths += ["#{config.root}/lib"]
config.eager_load_paths += ["#{config.root}/lib/**/"]

@darkside
Copy link

darkside commented Jul 4, 2013

Yeah mine are sitting under app/workers as well, and I have on my application.rb:

config.autoload_paths += %W(#{config.root}/app/workers)

😕

@kshnurov
Copy link
Author

kshnurov commented Jul 4, 2013

Yeah, now it works. Thank you!

@kshnurov kshnurov closed this as completed Jul 4, 2013
@kshnurov kshnurov reopened this Jul 4, 2013
@kshnurov
Copy link
Author

kshnurov commented Jul 4, 2013

Now I'm getting that error only with big queues - first 25 workers starting ok, all the next failing.
I've tried to add sidekiq-limit_fetch gem and limit all queues to 20 workers as a workaround - it didn't help. All workers, except first 25, failing immediately after start.

@kshnurov
Copy link
Author

kshnurov commented Jul 4, 2013

Even when sidekiq is paused (bundle exec sidekiqctl quiet) - all workers fail immediately after adding to queue.

@darkside
Copy link

darkside commented Jul 4, 2013

Try using config.eager_load_paths += instead of autoload. See https://github.com/mperham/sidekiq/wiki/FAQ (Why doesn't Sidekiq autoload my Rails application code?)

@kshnurov
Copy link
Author

kshnurov commented Jul 4, 2013

I'm already using both.

@darkside
Copy link

darkside commented Jul 4, 2013

Only other thing I can think about is there could be something else breaking and preventing your class from being loaded. I never had your second issue, it either always found out the class or never found the class. 😐

@dmeremyanin
Copy link
Contributor

Try to explicitly require your worker code before the application is defined.
In config/application.rb:

require './app/workers/unique_text_worker'

module YourApplication
  class Application < Rails::Application
    # ...

@kshnurov
Copy link
Author

kshnurov commented Jul 4, 2013

dimko, it didn't help. I've updated sidekiq from 2.14.0 to 2.14.4 - still nothing.

@TheCorp
Copy link

TheCorp commented Jul 8, 2013

Another option is to try initializing (using in any way) the class in the sidekiq initializer. That should make sure its loaded into memory before any of the workers get to using it.

@Bodacious
Copy link

I'm having a similar issue just now...

All of my mailer jobs are failing because the class can't be found: undefined class/module MemberMailer

All mailers are in app/mailers/*

Rails version 3.2.14
Sidekiq version 2.13.0

We go live tomorrow! Any advice would help right now

@kshnurov
Copy link
Author

In my case I had old Sidekiq process that was not terminated and was hanging in "terminating" status for a week. Try to kill and restart all sidekiq processes.

@Bodacious
Copy link

Hey @kshnurov thanks for the feedback.

This was actually a developer error, I'd removed the Sidekiq.configure_client block from the initializer 😟

@ghost
Copy link

ghost commented Aug 2, 2013

If this is happening locally, make sure that config.cache_classes = true in development.rb. The docs say that config.eager_load_paths only works if class caching is enabled (this sucks for development though).

http://guides.rubyonrails.org/v3.2.13/configuring.html#rails-general-configuration

config.eager_load_paths accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the app directory of the application.

This worked for me in development with Rails 3.2.13, Sidekiq 2.12.0.

@mperham
Copy link
Collaborator

mperham commented Aug 2, 2013

Sidekiq always eager loads due to thread safety. It does not support development mode and ignores cache_classes.

On Aug 1, 2013, at 18:48, Christopher Chow notifications@github.com wrote:

If this is happening locally, make sure that config.cache_classes = true. The docs say that config.eager_load_paths only works if class caching is enabled (this sucks for development though).

http://guides.rubyonrails.org/v3.2.13/configuring.html#rails-general-configuration

config.eager_load_paths accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the app directory of the application.


Reply to this email directly or view it on GitHub.

@mperham mperham closed this as completed Aug 3, 2013
@vkeziah
Copy link

vkeziah commented Dec 10, 2014

I am getting NameError (uninitialized constant Api::V1::EmailController::ResponseWorker) when I try to call workers from my controller , I added autoload paths still getting this error , can anyone please help me

@bcobb
Copy link

bcobb commented Dec 10, 2014

@vkeziah Some information that would be helpful in getting to the bottom of your problem:

  1. What version of Ruby/Rails/Sidekiq are you using?
  2. Does this error occur in every environment? Only development? Only production?
  3. What is the path to your worker?
  4. What are the first few lines of the worker file - at least until include Sidekiq::Worker?
  5. What is the line of code in the controller that sends a job to the worker?

@vkeziah
Copy link

vkeziah commented Dec 10, 2014

  1. I am using ruby 2.1.5, rails - 4.1.x , sidekiq -3.1.x
  2. I check in only in development
  3. my workers are reside in app/workers folder
  4. require 'sidekiq'
    require 'logger'

class ResponseWorker
include Sidekiq::Worker

  1. ResponseWorker.perform_async(id)

Please let me know if you nee any more information

@seuros
Copy link
Collaborator

seuros commented Dec 10, 2014

@vkeziah : upgrade to sidekiq 3.3.x and try again.

@vkeziah
Copy link

vkeziah commented Dec 10, 2014

yep it works ... thanks

However I am facing wiht another problem .. when I try to find the records from the db I am getting error stack level too deep , not sure where the error is but I am suspecting that its with db connection and thought that it was unable to establish the connection with db to find the records.

Can you please let me know how to log the exact errors and way to work with database from workers.

@sidekiq sidekiq locked and limited conversation to collaborators Dec 10, 2014
@mperham
Copy link
Collaborator

mperham commented Dec 10, 2014

Please don't hijack old issues; open your own issue. Usage questions belong on the mailing list.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants