Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

## [Unreleased]


### Changed

- The Overview's "Active Jobs" card no longer counts failed jobs. It was the sum of ready, scheduled, in-progress and failed jobs, and since failed jobs pile up until someone retries or discards them while the others drain within seconds, it usually showed the same number as the Failed card. It now counts the jobs waiting to run or running: ready, scheduled, in-progress and blocked. Failed jobs keep their own card. Expect the number to drop after upgrading.

### Added

- "Blocked" card on the Overview, counting jobs held back by a concurrency limit (`limits_concurrency`) until a slot frees up. They were not shown anywhere on the dashboard before. Like the other cards, it reads its execution table (`solid_queue_blocked_executions`), not the jobs table.

### Fixed

- The `redirect_to` parameter on Retry/Discard (failed jobs), Execute (scheduled jobs) and Pause/Resume (queues) was passed straight to `redirect_to`, so a crafted link or form could send the user to another site after the action. Hosts on Rails' default open-redirect protection (`load_defaults 7.0` or later) got a 500 error instead, after the action had already run. Only paths within the dashboard are followed now, checked with Rails' `url_from`; anything else (other hosts, protocol-relative or backslash URLs, other schemes, paths outside the dashboard, or paths Rails can't parse) falls back to the page's usual redirect.
- Retrying a failed job could leave it with no execution at all, so it never ran again and was shown as pending forever. The monitor moved the job back to the ready queue and deleted its failed execution itself, inside an `ActiveRecord::Base` transaction. That is the app's primary database: when Solid Queue has its own database (`config.solid_queue.connects_to`, the Rails 8 default), the two steps committed separately. A worker could pick the job up in between and fail it again, Solid Queue recorded that failure on the same failed execution, and the monitor then deleted it. Retry, per row and bulk, now calls Solid Queue's own `FailedExecution#retry`, which does both in one transaction on Solid Queue's database. Retried jobs now also get their execution counters reset (so `retry_on ... attempts:` starts over) and respect `limits_concurrency`, as a retry from Solid Queue itself does. Retrying a failed job that someone else retried or discarded after it was loaded no longer raises an error, and a bulk retry now counts a job whose retry raises (e.g. a lock timeout) as failed and carries on with the rest instead of stopping halfway with an error page. The service's success message now reads "Job queued for retry", since a job with a concurrency limit can go to blocked executions instead of the ready queue.



## [2.4.0] - 2026-11-17

### Added
Expand Down
6 changes: 5 additions & 1 deletion app/services/solid_queue_monitor/stats_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ class StatsCalculator
def self.calculate
scheduled = SolidQueue::ScheduledExecution.count
ready = SolidQueue::ReadyExecution.count
blocked = SolidQueue::BlockedExecution.count
failed = SolidQueue::FailedExecution.count
in_progress = SolidQueue::ClaimedExecution.count
recurring = SolidQueue::RecurringTask.count

{
active_jobs: ready + scheduled + in_progress + failed,
# Jobs waiting to run or running. Failed jobs are left out: they only
# run again after a retry, and have their own card.
active_jobs: ready + scheduled + in_progress + blocked,
scheduled: scheduled,
ready: ready,
blocked: blocked,
failed: failed,
in_progress: in_progress,
recurring: recurring
Expand Down
1 change: 1 addition & 0 deletions app/views/solid_queue_monitor/overview/_stats.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<%= render 'stat_card', title: 'Ready', value: @stats[:ready] %>
<%= render 'stat_card', title: 'In Progress', value: @stats[:in_progress] %>
<%= render 'stat_card', title: 'Scheduled', value: @stats[:scheduled] %>
<%= render 'stat_card', title: 'Blocked', value: @stats[:blocked] %>
<%= render 'stat_card', title: 'Recurring', value: @stats[:recurring] %>
<%= render 'stat_card', title: 'Failed', value: @stats[:failed] %>
</div>
Expand Down
8 changes: 8 additions & 0 deletions spec/factories/solid_queue_factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
scheduled_at { 1.hour.from_now }
end

factory :solid_queue_blocked_execution, class: 'SolidQueue::BlockedExecution' do
association :job, factory: :solid_queue_job
queue_name { 'default' }
priority { 0 }
concurrency_key { 'TestJob/1' }
expires_at { 1.hour.from_now }
end

factory :solid_queue_failed_execution, class: 'SolidQueue::FailedExecution' do
association :job, factory: :solid_queue_job
error { 'StandardError: Test error message' }
Expand Down
9 changes: 9 additions & 0 deletions spec/requests/solid_queue_monitor/overview_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
expect(response.body).to include('Active Jobs')
end

it 'shows the number of blocked jobs' do
create_list(:solid_queue_blocked_execution, 2)

get '/'

card = Nokogiri::HTML5(response.body).at_xpath("//div[@class='stat-card'][h3[normalize-space()='Blocked']]")
expect(card.at_css('p').text.strip).to eq('2')
end

it 'displays navigation links' do
get '/'

Expand Down
12 changes: 10 additions & 2 deletions spec/services/solid_queue_monitor/stats_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
create(:solid_queue_scheduled_execution)
create(:solid_queue_ready_execution)
create(:solid_queue_claimed_execution)
create(:solid_queue_blocked_execution)
end

it 'returns a hash with all required statistics' do
Expand All @@ -18,6 +19,7 @@
:active_jobs,
:scheduled,
:ready,
:blocked,
:failed,
:in_progress,
:recurring
Expand All @@ -29,18 +31,24 @@

expect(stats[:scheduled]).to eq(1)
expect(stats[:ready]).to eq(1)
expect(stats[:blocked]).to eq(1)
expect(stats[:failed]).to eq(1)
expect(stats[:in_progress]).to eq(1)
expect(stats[:recurring]).to eq(0)
end

it 'derives active_jobs from execution table counts' do
it 'counts ready, scheduled, in-progress and blocked jobs as active' do
stats = described_class.calculate

expected_active = stats[:ready] + stats[:scheduled] + stats[:in_progress] + stats[:failed]
expected_active = stats[:ready] + stats[:scheduled] + stats[:in_progress] + stats[:blocked]
expect(stats[:active_jobs]).to eq(expected_active)
end

it 'does not count failed jobs as active' do
expect { create(:solid_queue_failed_execution) }
.not_to(change { described_class.calculate[:active_jobs] })
end

it 'does not query the jobs table for counts' do
allow(SolidQueue::Job).to receive(:count).and_call_original
described_class.calculate
Expand Down
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@
t.datetime :created_at, null: false
end

create_table :solid_queue_blocked_executions, force: true do |t|
t.integer :job_id, null: false
t.string :queue_name, null: false
t.integer :priority, default: 0, null: false
t.string :concurrency_key, null: false
t.datetime :expires_at, null: false
t.datetime :created_at, null: false
end

create_table :solid_queue_pauses, force: true do |t|
t.string :queue_name, null: false
t.datetime :created_at, null: false
Expand Down
5 changes: 5 additions & 0 deletions spec/support/solid_queue_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class ClaimedExecution < ApplicationRecord
belongs_to :job
end

class BlockedExecution < ApplicationRecord
self.table_name = 'solid_queue_blocked_executions'
belongs_to :job
end

class Pause < ApplicationRecord
self.table_name = 'solid_queue_pauses'
end
Expand Down
Loading