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?"
end
end
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 6.0.2.1)
> 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!