0
0
Ruby on Railsframework~10 mins

Job retries and error handling 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 number of retries for a job.

Ruby on Rails
class MyJob < ApplicationJob
  retry_on StandardError, wait: 5.seconds, attempts: [1]
  def perform
    # job code here
  end
end
Drag options to blanks, or click blank then click option'
A5
B10
C0
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Setting attempts to 0 disables retries.
Using a string instead of a number for attempts.
2fill in blank
medium

Complete the code to handle a specific error type with a custom retry wait time.

Ruby on Rails
class MyJob < ApplicationJob
  retry_on [1], wait: 10.seconds, attempts: 3
  def perform
    # job code here
  end
end
Drag options to blanks, or click blank then click option'
AStandardError
BActiveRecord::RecordNotFound
CNet::OpenTimeout
DArgumentError
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic error like StandardError when a specific error is needed.
Choosing an error unrelated to network issues.
3fill in blank
hard

Fix the error in the retry_on syntax to correctly retry on exceptions.

Ruby on Rails
class MyJob < ApplicationJob
  retry_on StandardError, wait: [1], attempts: 4
  def perform
    # job code here
  end
end
Drag options to blanks, or click blank then click option'
A5.seconds
B5
C5s
Dseconds(5)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a plain number instead of a duration.
Using invalid syntax like '5s' or 'seconds(5)'.
4fill in blank
hard

Fill both blanks to correctly rescue an error and retry the job with a delay.

Ruby on Rails
class MyJob < ApplicationJob
  rescue_from [1] do |exception|
    retry_job wait: [2]
  end
  def perform
    # job code here
  end
end
Drag options to blanks, or click blank then click option'
AActiveRecord::Deadlocked
BStandardError
C10.seconds
D5.minutes
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic error instead of the specific deadlock error.
Setting the wait time to a non-duration value.
5fill in blank
hard

Fill all three blanks to create a job that retries on two errors with different wait times.

Ruby on Rails
class MyJob < ApplicationJob
  retry_on [1], wait: [2], attempts: 3
  retry_on [3], wait: 20.seconds, attempts: 2
  def perform
    # job code here
  end
end
Drag options to blanks, or click blank then click option'
ANet::OpenTimeout
B15.seconds
CActiveRecord::Deadlocked
DStandardError
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up error classes and wait times.
Using non-duration values for wait times.