Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a basic Active Job class.
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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a queue name that is not defined in the system
Forgetting to set a queue name
✗ Incorrect
The queue_as method sets the queue name. default is the standard queue name in Rails Active Job.
2fill in blank
mediumComplete the code to enqueue a job to run asynchronously.
Ruby on Rails
MyJob.[1](user_id) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
perform_now which runs the job immediatelyUsing non-existent methods like
run_async✗ Incorrect
perform_later enqueues the job to run asynchronously in the background.
3fill in blank
hardFix the error in the job class to correctly access the argument.
Ruby on Rails
class NotifyUserJob < ApplicationJob def perform([1]) UserMailer.welcome_email([1]).deliver_now end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic name like
args without unpackingUsing
user when only the ID is passed✗ Incorrect
The job receives user_id as an argument, which is passed to the mailer.
4fill in blank
hardFill both blanks to schedule a job to run 5 minutes from now.
Ruby on Rails
MyJob.[1](wait: [2].minutes).perform_later
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
perform_later without set for schedulingUsing wrong wait time values
✗ Incorrect
set(wait: 5.minutes) schedules the job to run after 5 minutes.
5fill in blank
hardFill all three blanks to create a job that retries 3 times with 10 seconds delay between attempts.
Ruby on Rails
class RetryJob < ApplicationJob [1] StandardError, wait: [2], attempts: [3] def perform # job code end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
rescue_from which handles exceptions differentlyNot specifying wait time or attempts correctly
✗ Incorrect
retry_on sets retry behavior with wait time and attempts count.