ActiveJob Vs ApplicationJob

A very quick clarification on ActiveJob and ApplicationJob

If you are looking up documentation about the Jobs functionality within Rails you can occasionally see that the sample Jobs class appears to inherit from two different classes.

Some examples will show something like;

class MyJob < ActiveJob::Base
end

Whilst others will be more like;

class MyJob < ApplicationJob
end

When you create a new Rails 5 project a file is created within app/jobs called application_job.rb and in it we create a class called ApplicationJob which inherits from ActiveJob::Base.

class ApplicationJob < ActiveJob::Base
end

The chances are if you’re reading a guide that mentions ApplicationJob then it was created assuming a Rails 5 starting point, guides or sample code mentioning ActiveJob::Base are ones that don’t assume you have the application_job.rb file.

Best practice is to use ApplicationJob and create the empty class if you don’t have one already – this will allow you to add code which can be inherited by all of your Jobs.

Recent posts View all

Web DevProductivity

Keeping on top of website updates

Learn what website updates are, what they entail, why they are important, and how we can help

Freelancing

Getting the most out of your agency

Here are some tips based on years of working with, for, and as an agency on how to get the most out of any work you do.