Reputation: 1687
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
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
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