skip to content

In a Rails 8.1 app on Solid Queue, what happens to an Active Job whose perform raises when the job declares no retry_on?

level: juniorimportance: should knowfreq 45%

answer

  1. no automatic retry anywhere
  2. after_discard runs, then the error re-raises
  3. solid_queue_failed_executions row
  4. retry or discard from Mission Control
  5. a manual retry resets the counters

basics

~20 s

Nothing retries it. Active Job runs any after_discard callbacks and re-raises, and Solid Queue records a failed execution holding the error class, message and backtrace. The job waits there until someone retries or discards it, from Mission Control Jobs or the console.

solid answer

~40 s

Active Job wraps `perform` in `rescue_from` handling; if no handler matches the exception (or its `cause`), it runs the class's `after_discard` callbacks and re-raises. Solid Queue has **no retry mechanism of its own**: it marks the job failed by inserting a row into `solid_queue_failed_executions` with the exception class, message and backtrace. That row is not cleared with finished jobs; it stays until someone acts. Mission Control Jobs lists failed jobs with retry and discard buttons, and the console offers `SolidQueue::FailedExecution#retry` and `#discard`. A manual retry dispatches the same job again and resets its `executions` and `exception_executions` counters, so any `retry_on` rules start counting from zero. To retry transient errors automatically, declare `retry_on` in the job or in `ApplicationJob`.

code

ruby · 8 lines
ruby
# bin/rails console in production
SolidQueue::FailedExecution.count            # => 14

SolidQueue::FailedExecution.includes(:job).find_each do |failed|
  next unless failed.exception_class == "Errno::ECONNREFUSED"

  failed.retry   # same job_id, executions reset to 0
end

go deeper

for a junior

Remember that without retry_on a failed job is not retried: Solid Queue keeps it as a failed execution until someone retries or discards it.

for a middle

Explain the path: no matching handler, after_discard runs, the error re-raises, a failed execution row is written, and a manual retry resets the counters.

for a senior

Set a deliberate default policy in ApplicationJob, alert on the failed-execution count, and plan bulk retries after outages without replaying permanent failures.

for a principal

Decide who owns failed jobs across teams and what the default policy for transient errors should be, since retrying everything has side-effect costs.

## The path of an unhandled exception Rails 8 apps run **Active Job** on **Solid Queue** in production by default. Solid Queue stores jobs in database tables and leaves every decision about errors to Active Job. Follow a job that sends print files to a press, `PrintFileJob`, when its `perform` raises `Errno::ECONNREFUSED` and the class declares no error rules: 1. A Solid Queue worker thread claims the job and calls `ActiveJob::Base.execute`, which builds the job and calls `perform_now`. 2. `perform_now` increments `executions` and runs `perform`, which raises. 3. Active Job looks for a `rescue_from` handler matching the exception, and then one matching the exception's `cause`. `retry_on` and `discard_on` are such handlers; here there are none. 4. With no handler, Active Job runs the class's `after_discard` callbacks and **re-raises** the exception. 5. Solid Queue catches it in the worker, records a **failed execution** for the job and releases the thread for the next job. Nothing schedules another attempt. A job that fails once on a network blip stays failed. ## What Solid Queue keeps The failed execution is a row in `solid_queue_failed_executions`, pointing at the job row in `solid_queue_jobs`, with the error serialized as JSON: | Stored | Meaning | |---|---| | `exception_class` | for example `Errno::ECONNREFUSED` | | `message` | the exception message | | `backtrace` | the stack, truncated if the column has a size limit | | the job row | class name, queue, arguments, `executions` count | Finished jobs are cleared on a schedule (`clear_finished_jobs_after`, one day by default), but **failed jobs are kept** until they are retried or discarded, so an unwatched list only grows. ## Retrying or discarding by hand - **Mission Control Jobs**, the Rails dashboard for Active Job backends, lists failed jobs with their errors and offers retry and discard, one at a time or in bulk. - From the console: ```ruby failed = SolidQueue::FailedExecution.last failed.exception_class # => "Errno::ECONNREFUSED" failed.retry # back to ready, counters reset # or, for a job that should never run again: # failed.discard # deletes the job and its failed execution ``` A manual retry does not create a new job: it sets `executions` back to zero, empties `exception_executions` in the stored job data and makes the same job ready again, so the `job_id` is unchanged and any `retry_on` limits start over. ## Watching the failed list Failed executions are only useful if someone looks at them: - Track `SolidQueue::FailedExecution.count` as a metric and alert when it climbs faster than usual. - Group failures by `exception_class` after an incident, to tell one outage apart from several bugs. - Retry in bulk only the failures the outage caused; a failure caused by a bug will simply fail again. - Discard jobs whose work is no longer wanted, such as print files for a cancelled order, instead of letting them pile up. - Review the list after each deploy, because a new bug usually shows up there first. An `after_discard` callback can also mark the affected record, for example setting an order's state to `print_failed`, so the failure is visible inside the application and not only in the jobs dashboard. ## Why there is no default retry The Active Job guide says it plainly: a failed job is not retried unless configured otherwise. Rails cannot know whether an error is transient (a timeout) or permanent (a deleted record, a bug), and retrying a permanent failure only repeats it, perhaps with side effects each time. Some other backends retry everything by default; Solid Queue deliberately does not, and a failed execution is the safe resting place. ## Setting a default policy Most apps add a small policy to `ApplicationJob` so every job retries the errors that are usually transient and gives up on the ones that never fix themselves: ```ruby class ApplicationJob < ActiveJob::Base retry_on ActiveRecord::Deadlocked, wait: 5.seconds, attempts: 3 retry_on Net::OpenTimeout, Net::ReadTimeout, wait: :polynomially_longer, attempts: 5 end ``` Things to keep in mind: - once `retry_on` runs out of attempts without a block, the error is re-raised and the job still ends as a failed execution, now with a higher `executions` count; - a `rescue_from` handler that swallows the error makes the job finish as **successful**, and nothing is kept for inspection; - someone has to own the failed list: alert on its size, and review it after deploys.

  • A job's rescue_from handler logs the error and returns. What does Solid Queue record?
    The job finishes normally. The handler counted as handling the exception, so `perform_now` returns, the worker sees success and the job is marked finished, later cleared with other finished jobs. No failed execution is created, so the failure is visible only in the logs. Re-raise inside the handler if the job should still count as failed.
  • After fixing the bug, you retry a failed job that had used all 5 retry_on attempts. Does it get 5 more?
    Yes. `SolidQueue::FailedExecution#retry` resets `executions` and `exception_executions` before dispatching the job again, so `retry_on` counts from zero and the job gets its full set of attempts. That is usually what you want after a fix, but it also means retrying a still-broken job repeats the whole backoff sequence.

  • Saying Rails retries every failed job a few times by default
  • Believing Solid Queue deletes failed jobs with the finished-job cleanup
  • Expecting Solid Queue's own config/queue.yml to set a retry count
  • Treating a swallowed rescue_from error as a failed execution
  • Assuming a manual retry from Mission Control creates a new job_id