Background on Rails – why do you need to learn all the background job APIs?

Rails has a new library called ActiveJob, the idea of this library is to make it easier to create background jobs without worring about what library to use, and the specific API for each one, and even changing it if a better one comes out in the future without changing your application.

ActiveJob will keep one simple API and it already provides an in memory implementation that you can use to test and in development environment, but do not forget to select a real driver for your production environment.

ActiveJob is so cool, that it out of the box, allows you to do things like this:

MyMailer.prepare_email(param1, param2, param3).deliver_later

And the email will be delivered by the job queue, and only this would already be a huge performance improvement for a lot of shitty web applications around.

Of course it is not just that, you can create your own jobs with the simple command:

rails g job MySuperComplexLogic

that will just create a file app/jobs/my_super_complex_logic_job.rb according to the name you’ve passed to the generator.

The file looks like any other Ruby class, because it is a simple ruby class as you can see bellow: