0
0
Ruby on Railsframework~10 mins

Job priorities and queues in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the queue name for a job.

Ruby on Rails
class MyJob < ApplicationJob
  queue_as :[1]

  def perform(*args)
    # job code here
  end
end
Drag options to blanks, or click blank then click option'
Adefault
Burgent
Clow_priority
Dmailers
Attempts:
3 left
💡 Hint
Common Mistakes
Using a queue name that is not defined in the system.
Forgetting to set the queue name when needed.
2fill in blank
medium

Complete the code to enqueue a job with high priority queue.

Ruby on Rails
MyJob.set(queue: :[1]).perform_later(user_id)
Drag options to blanks, or click blank then click option'
Adefault
Burgent
Clow_priority
Dmailers
Attempts:
3 left
💡 Hint
Common Mistakes
Using the default queue when a specific priority is needed.
Misspelling the queue name.
3fill in blank
hard

Fix the error in the job class to correctly set the queue name.

Ruby on Rails
class ReportJob < ApplicationJob
  queue_as [1]

  def perform(report_id)
    # generate report
  end
end
Drag options to blanks, or click blank then click option'
A"reports"
B'reports'
Creports
D:reports
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of symbols for queue names.
Omitting the colon before the queue name.
4fill in blank
hard

Fill both blanks to create a job that retries 5 times and uses the 'critical' queue.

Ruby on Rails
class CriticalJob < ApplicationJob
  queue_as [1]
  retry_on [2], attempts: 5

  def perform(task_id)
    # critical task
  end
end
Drag options to blanks, or click blank then click option'
A:critical
BStandardError
CRuntimeError
D:default
Attempts:
3 left
💡 Hint
Common Mistakes
Using string queue names instead of symbols.
Using incorrect error classes for retry.
5fill in blank
hard

Fill all three blanks to define a job that uses the 'mailers' queue, discards after 3 attempts, and performs with a user email.

Ruby on Rails
class UserMailerJob < ApplicationJob
  queue_as [1]
  discard_on [2], attempts: 3

  def perform([3])
    # send email
  end
end
Drag options to blanks, or click blank then click option'
A:mailers
BStandardError
Cemail
D:default
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of symbols for queue names.
Using wrong error classes for discard.
Incorrect parameter names in perform method.