Sidekiq: Uninitialized constant Sidekiq::Extensions::DelayedMailer

Created on 9 Jun 2017  Â·  9Comments  Â·  Source: mperham/sidekiq

Ruby version: ruby 2.4.1p111
Sidekiq / Pro / Enterprise version(s): 5.0.2

I'm trying to use the delayed extensions to send emails asynchronously:

UserMailer.delay.welcome(user.id)

But I'm getting this error in Sidekiq when the worker starts:

Error stacktrace:

2017-06-08T23:13:50.217Z 42380 TID-ouzw5lglg Sidekiq::Extensions::DelayedMailer JID-d84c6ccda407da386ab90a00 INFO: start
2017-06-08T23:13:50.219Z 42380 TID-ouzw5lglg Sidekiq::Extensions::DelayedMailer JID-d84c6ccda407da386ab90a00 INFO: fail: 0.002 sec
2017-06-08T23:13:50.219Z 42380 TID-ouzw5lglg WARN: {"context":"Job raised exception","job":{"class":"Sidekiq::Extensions::DelayedMailer","args":["---\n- !ruby/class 'UserMailer'\n- :welcome\n- - 2646e8d8-d780-4a5b-b94e-8b5dd166f5e5\n"],"retry":true,"queue":"default","jid":"d84c6ccda407da386ab90a00","created_at":1496963630.216139,"enqueued_at":1496963630.216407,"error_message":"uninitialized constant Sidekiq::Extensions::DelayedMailer","error_class":"NameError","failed_at":1496963630.2196102,"retry_count":0},"jobstr":"{\"class\":\"Sidekiq::Extensions::DelayedMailer\",\"args\":[\"---\\n- !ruby/class 'UserMailer'\\n- :welcome\\n- - 2646e8d8-d780-4a5b-b94e-8b5dd166f5e5\\n\"],\"retry\":true,\"queue\":\"default\",\"jid\":\"d84c6ccda407da386ab90a00\",\"created_at\":1496963630.216139,\"enqueued_at\":1496963630.216407}"}
2017-06-08T23:13:50.220Z 42380 TID-ouzw5lglg WARN: NameError: uninitialized constant Sidekiq::Extensions::DelayedMailer
2017-06-08T23:13:50.220Z 42380 TID-ouzw5lglg WARN: /Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:237:in `block in constantize'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:236:in `each'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:236:in `inject'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:236:in `constantize'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:137:in `block (5 levels) in dispatch'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/rails.rb:42:in `block in call'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.0/lib/active_support/execution_wrapper.rb:85:in `wrap'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.0/lib/active_support/reloader.rb:68:in `block in wrap'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.0/lib/active_support/execution_wrapper.rb:85:in `wrap'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.0/lib/active_support/reloader.rb:67:in `wrap'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/rails.rb:41:in `call'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:136:in `block (4 levels) in dispatch'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:215:in `stats'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:131:in `block (3 levels) in dispatch'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/job_logger.rb:7:in `call'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:130:in `block (2 levels) in dispatch'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/job_retry.rb:72:in `global'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:129:in `block in dispatch'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/logging.rb:44:in `with_context'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/logging.rb:38:in `with_job_hash_context'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:128:in `dispatch'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:168:in `process'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:85:in `process_one'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/processor.rb:73:in `run'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/util.rb:16:in `watchdog'
/Users/hashlabs/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sidekiq-5.0.2/lib/sidekiq/util.rb:25:in `block in safe_thread'

My initializer:

# config/initializers/sidekiq.rb

Sidekiq::Extensions.enable_delay!

I've updated to the latest version of sidekiq 5.0.2 but I'm still seeing this error, what could be causing it? I'm also using Rails 5.1.0

Most helpful comment

I ran into the same issue, config.eager_load = true fixed it.

A simple app to reproduce

git clone [email protected]:colderis/sidekiq_issue.git sidekiq_issue
cd sidekiq_issue
bin/setup

Then start sidekiq:

bundle exec sidekiq

Finally open the rails console bin/rails c and paste the following:

NotificationMailer.delay.simple_email

Sidekiq should now report the error: uninitialized constant Sidekiq::Extensions::DelayedMailer.

All 9 comments

I had to add eager_loading on the development.rb:

config.eager_load = true

But this was kind of weird to me, should I get away from using the delayed extensions for emails?

I can't explain why it's not working for you.

On Jun 8, 2017, at 18:04, Carlos Martinez notifications@github.com wrote:

I had to add eager_loading on the development.rb:

config.eager_load = true
But this was kind of weird to me, should I get away from using the delayed extensions for emails?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

I guess it's like this:
1) eagar load is false
2) ActionMailer not loaded
3) Sidekiq worker try to run Sidekiq::Extensions::DelayedMailer, not UserMailer
4.1) UserMailer not loaded yet
4.2) so ActionMailer not loaded yet
4.3) so sidekiq/extensions/action_mailer not required yet
4.4) so Sidekiq::Extensions::DelayedMailer not defined

and eager loading solves it since it loads
UserMailer => ActionMailer => sidekiq/extensions/action_mailer => Sidekiq::Extensions::DelayedMailer

Edit: I guess it can be fixed by requiring the files when enable_delay! is called, instead of in on_load block

Can you give us a small app which reproduces the problem?

I ran into the same issue, config.eager_load = true fixed it.

A simple app to reproduce

git clone [email protected]:colderis/sidekiq_issue.git sidekiq_issue
cd sidekiq_issue
bin/setup

Then start sidekiq:

bundle exec sidekiq

Finally open the rails console bin/rails c and paste the following:

NotificationMailer.delay.simple_email

Sidekiq should now report the error: uninitialized constant Sidekiq::Extensions::DelayedMailer.

Thank you @colderis, the issue has been fixed.

@mperham I'm seeing this same issue on sidekiq-pro 3.5.2, which is the latest. Any plans to also apply this fix there?

@rubemz The problem was fixed in Sidekiq 5.0.4. If you still see the problem, please open your own issue and supply all the info requested.

I think sometimes this happens due to spring. Try the following steps:

  1. stop the server
  2. close the console
  3. run bin/spring stop
  4. then again run the console/server

it should work now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mperham picture mperham  Â·  4Comments

agrobbin picture agrobbin  Â·  4Comments

nikhilm492 picture nikhilm492  Â·  4Comments

aglushkov picture aglushkov  Â·  3Comments

smanolloff picture smanolloff  Â·  3Comments