Complete the code to define a basic Active Job class in Rails.
class MyJob < ApplicationJob queue_as :default def [1] puts "Job is running" end end
The perform method is the standard method that Rails calls when running a job.
Complete the code to enqueue a job to run asynchronously.
MyJob.[1]The perform_later method enqueues the job to run asynchronously in Rails.
Fix the error in scheduling a job to run 5 minutes from now.
MyJob.[1](wait: 5.minutes)
perform_now which runs the job immediately without delay.To schedule a job with a delay, use perform_later with the wait option.
Fill both blanks to create a scheduled job that runs at a specific time.
MyJob.[1](wait_until: [2])
perform_now which does not support scheduling.Time.now which is less preferred than Time.current in Rails.Use perform_later with wait_until set to a future time like Time.current + 1.hour to schedule the job.
Fill all three blanks to define a job class with a custom queue and perform method.
class CustomJob < ApplicationJob queue_as [1] def [2] puts [3] end end
The queue_as sets the queue name, perform is the method Rails calls, and the string is printed inside the method.