Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 555
Josh Hunter Avatar asked Jun 16 '15 21:06

Josh Hunter


2 Answers

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.

like image 156
Karmie Avatar answered Sep 18 '22 14:09

Karmie


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.

like image 45
Josh Hunter Avatar answered Sep 22 '22 14:09

Josh Hunter