Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to enqueue a job to run asynchronously.
Ruby on Rails
MyJob.perform_later([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using perform_now instead of perform_later
Forgetting to pass the job argument
Calling enqueue which is not a method here
✗ Incorrect
Use perform_later with the job argument to enqueue it asynchronously.
2fill in blank
mediumComplete the code to define a job class inheriting from ActiveJob.
Ruby on Rails
class MyJob < [1] def perform(user_id) # job code here end end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Inheriting from ApplicationJob without defining it
Using just ActiveJob instead of ActiveJob::Base
Using a non-existent class JobBase
✗ Incorrect
Jobs inherit from ActiveJob::Base to get job functionality.
3fill in blank
hardFix the error in the job perform method to accept multiple arguments.
Ruby on Rails
def perform([1]) # code using user_id and message end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Listing multiple arguments without commas
Using a single argument without splat for multiple values
Using an undefined variable name
✗ Incorrect
Use *args to accept multiple arguments in the perform method.
4fill in blank
hardFill both blanks to schedule a job to run 5 minutes from now.
Ruby on Rails
MyJob.set(wait: [1]).perform_later([2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using seconds instead of minutes for delay
Passing the whole user object instead of user ID
Omitting the set method
✗ Incorrect
Use set(wait: 5.minutes) to delay the job, and pass the correct argument.
5fill in blank
hardFill all three blanks to retry a job on failure with a maximum of 3 attempts and 5 seconds wait between retries.
Ruby on Rails
class RetryJob < ActiveJob::Base retry_on [1], 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 the wrong error class
Mixing up wait time units
Setting attempts to zero or negative
✗ Incorrect
Use retry_on RuntimeError with wait and attempts options to retry the job.