Quick tips: Running Rails Jobs on the terminal

You can run Rails Jobs without having to configure any backend. The only things you need are the Rails console and the perform_now method.

Suppose you created a job called PrintHappy:

rails generate job print_happy 

You can navigate to the app/jobs folder and populate the perform method with anything you need:

class PrintHappyJob < ApplicationJob
  queue_as :default

  def perform(*args)
    puts "I am very happy, are you happy too?"

Now the only thing you need is to run rails c and invoke the perform_now method on PrintHappyJob:

> rails c                                                                   
Running via Spring preloader in process 5126
Loading development environment (Rails

> PrintHappyJob.perform_now()

Performing PrintHappyJob (Job ID: 7f8216f8-...) from Async(default) enqueued at 
I am very happy, are you happy too? 
Performed PrintHappyJob (Job ID: 7f8216f8-...) from Async(default) in 0.06ms

This executes the job immediately and makes debugging and development of jobs much easier

Thanks for reading!

Author image
Budapest, Hungary
Hey there, I'm Juan. A programmer currently living in Budapest. I believe in well-engineered solutions, clean code and sharing knowledge. Thanks for reading, I hope you find my articles useful!