Performance: Job retries and error handling
This affects server-side job processing speed and resource usage, indirectly impacting user experience by delaying background tasks.
class MyJob < ApplicationJob retry_on StandardError, wait: :exponentially_longer, attempts: 5 def perform(*args) # job logic end end
class MyJob < ApplicationJob retry_on StandardError def perform(*args) # job logic end end
| Pattern | Job Re-enqueues | Server Load | Queue Delay | Verdict |
|---|---|---|---|---|
| Unlimited immediate retries | Many rapid re-enqueues | High CPU and memory spikes | Long delays for other jobs | [X] Bad |
| Limited retries with exponential backoff | Few spaced re-enqueues | Balanced resource use | Minimal queue delays | [OK] Good |
retry_on method do in a Rails Active Job?retry_on purposeretry_on method tells Rails to retry a job if a certain error happens during execution.discard_on, which stops retries, retry_on allows automatic retrying.retry_on = automatic retry [OK]ActiveRecord::Deadlocked error with 3 attempts in Rails?retry_on(ActiveRecord::Deadlocked, attempts: 3).class MyJob < ApplicationJob
retry_on StandardError, attempts: 2
def perform
raise StandardError, "fail"
end
end
MyJob.perform_nowMyJob.perform_now is called?class ExampleJob < ApplicationJob
retry_on(StandardError, attempts: 3)
def perform
# job logic
end
endNet::OpenTimeout errors but discard immediately on ArgumentError. Which code correctly implements this behavior?Pass the test and this pattern moves unknown