Skip to content

NameError: uninitialized constant when using namespaced job classes #213

@raihanM99

Description

@raihanM99

I'm encountering an intermittent NameError: uninitialized constant when using namespaced Sidekiq job classes (e.g. DocumentAI::ProcessFileJob) with sidekiq-throttled. This happens even though the job classes are correctly defined, autoloaded by Zeitwerk, and run fine under normal conditions.

My job class is:

class DocumentAI::ProcessFileJob
  include Sidekiq::Job
  include Sidekiq::Throttled::Job

  sidekiq_throttle(
    concurrency: {
      limit: 2,
      key_suffix: ->(token, *rest) { token }
    }
  )
end

Error in my Rails log:

INFO  2025-06-13T06:24:37.788Z pid=9 tid=ktf9: /gems/ruby/3.2.0/gems/sidekiq-throttled-2.0.0/lib/sidekiq/throttled.rb:102:in `const_get': uninitialized constant DocumentAI (NameError)
be-1       | 
be-1       |         job_class = Object.const_get(message.fetch("wrapped") { message.fetch("class") { return false } })

This happens sporadically, especially after the worker boots, but not always reproducible — sometimes jobs run fine, sometimes this error pops up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions