Complete the code to set the queue name for a job.
class MyJob < ApplicationJob queue_as :[1] def perform(*args) # job code here end end
The queue_as method sets the queue name for the job. Here, default is the standard queue name.
Complete the code to enqueue a job with high priority queue.
MyJob.set(queue: :[1]).perform_later(user_id)Using set(queue: :urgent) enqueues the job to the 'urgent' queue, which is for high priority jobs.
Fix the error in the job class to correctly set the queue name.
class ReportJob < ApplicationJob queue_as [1] def perform(report_id) # generate report end end
The queue_as method expects a symbol for the queue name, so :reports is correct.
Fill both blanks to create a job that retries 5 times and uses the 'critical' queue.
class CriticalJob < ApplicationJob queue_as [1] retry_on [2], attempts: 5 def perform(task_id) # critical task end end
The job uses the :critical queue and retries on StandardError up to 5 times.
Fill all three blanks to define a job that uses the 'mailers' queue, discards after 3 attempts, and performs with a user email.
class UserMailerJob < ApplicationJob queue_as [1] discard_on [2], attempts: 3 def perform([3]) # send email end end
The job uses the :mailers queue, discards on StandardError after 3 attempts, and takes email as a parameter.