0
0
Ruby on Railsframework~10 mins

Active Job framework 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 enqueue a job to run asynchronously.

Ruby on Rails
MyJob.perform_later([1])
Drag options to blanks, or click blank then click option'
Auser_id
Bperform_now
Cenqueue
Dperform_later
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
2fill in blank
medium

Complete 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'
AApplicationJob
BActiveJob
CJobBase
DActiveJob::Base
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
3fill in blank
hard

Fix 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'
Auser_id, message
B*args
Cargs
Duser_id message
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
4fill in blank
hard

Fill 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'
A5.minutes
B10.seconds
Cuser.id
Duser_id
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
5fill in blank
hard

Fill 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'
AStandardError
B5.seconds
C3
DRuntimeError
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong error class
Mixing up wait time units
Setting attempts to zero or negative