0
0
Ruby on Railsframework~20 mins

Job retries and error handling in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rails Job Retry Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a job raises an exception in Active Job with default retry settings?
Consider a Rails Active Job that raises an exception during execution. What is the default behavior regarding retries and job failure?
Ruby on Rails
class ExampleJob < ApplicationJob
  def perform
    raise "Something went wrong"
  end
end

ExampleJob.perform_later
AThe job fails immediately without any retries.
BThe job is retried automatically 3 times before being discarded.
CThe job is retried infinitely until it succeeds.
DThe job is retried once and then discarded.
Attempts:
2 left
💡 Hint
Active Job does not retry by default; retry_on must be configured.
📝 Syntax
intermediate
2:00remaining
Which syntax correctly sets a custom retry count for a job in Rails Active Job?
You want to configure a job to retry only 5 times on failure. Which code snippet correctly sets this retry count?
A
class CustomRetryJob &lt; ApplicationJob
  retry_on StandardError, attempts: 5
  def perform
    # job code
  end
end
B
class CustomRetryJob &lt; ApplicationJob
  retry_on StandardError, retries: 5
  def perform
    # job code
  end
end
C
class CustomRetryJob &lt; ApplicationJob
  retry_on StandardError, max_retries: 5
  def perform
    # job code
  end
end
D
class CustomRetryJob &lt; ApplicationJob
  retry_on StandardError, retry_count: 5
  def perform
    # job code
  end
end
Attempts:
2 left
💡 Hint
Check the official Active Job retry_on method options.
🔧 Debug
advanced
2:00remaining
Why does this job never retry despite using retry_on?
Given the following job code, why does the job not retry after raising a RuntimeError?
Ruby on Rails
class NoRetryJob < ApplicationJob
  retry_on ArgumentError, attempts: 3

  def perform
    raise RuntimeError, "fail"
  end
end
ABecause RuntimeError is a subclass of ArgumentError, so it skips retry.
BBecause retry_on is set only for ArgumentError, not RuntimeError.
CBecause retry_on requires a block to retry the job.
DBecause attempts option is ignored for RuntimeError exceptions.
Attempts:
2 left
💡 Hint
Check which exception class retry_on is configured to handle.
state_output
advanced
2:00remaining
What is the state of a job after all retries are exhausted?
If a job configured with retry_on fails all retry attempts, what is the final state of the job in the queue system?
AThe job remains in the queue indefinitely waiting for manual retry.
BThe job is automatically rescheduled to run again after a delay.
CThe job is marked as failed and moved to the dead queue or discarded.
DThe job is deleted immediately without any record.
Attempts:
2 left
💡 Hint
Think about what happens when retries are exhausted in background job systems.
🧠 Conceptual
expert
3:00remaining
How can you implement exponential backoff for retries in Rails Active Job?
You want your job retries to wait longer after each failure, doubling the wait time each retry (exponential backoff). Which approach correctly implements this behavior?
AOverride the perform method to sleep for an exponentially increasing time before raising an error.
BSet attempts to a high number and rely on default retry intervals for exponential backoff.
CUse discard_on with a delay option that increases exponentially.
DUse retry_on with a block that re-enqueues the job with increasing wait times based on the retry count.
Attempts:
2 left
💡 Hint
Consider how retry_on blocks can customize retry behavior and delay.