Josh Hunter
Josh Hunter

Reputation: 1687

Uninitialized constant for my job ActiveJob

I'm trying to learn ActiveJob and I created a simple job to walk through the process. I'm pretty much stuck on step 1. I've got a my_job.rb file in app/jobs. That file contains this code:

class MyJob < ActiveJob::Base
  queue_as :default

  def perform(obj)
    puts obj
  end
end

If I go to my console and type in MyJob, it acts like the class doesn't exist...what am I missing?

:001 > MyJob NameError: uninitialized constant MyJob

Upvotes: 16

Views: 8424

Answers (3)

Sergio Gonzalez
Sergio Gonzalez

Reputation: 2200

I had to restart sidekiq too, in case you are using it.

Upvotes: 0

Karmie
Karmie

Reputation: 387

Make sure the job's filename ends with "_job.rb".

For example: a job called CheckDropboxAvailableSpaceJob should have its filename named check_dropbox_available_space_job.rb, not check_dropbox_available_space.rb.

Rails won't recognize it as a job if the filename doesn't have "_job" on the end.

Upvotes: 21

Josh Hunter
Josh Hunter

Reputation: 1687

I think this was resolved somewhat randomly...I probably restarted my server or something. As far as I can tell, every time a job is edited, the server has to be restarted in order for the changes to be picked up.

Upvotes: 1

Related Questions