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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Added

- Discard action on the Ready Jobs page, per row and as a "Discard Selected" bulk action, so ready jobs that no worker will ever claim (e.g. left on a queue that was renamed) can be removed from the UI. Like Discard on Failed Jobs and Reject on Scheduled Jobs, it marks each job finished and deletes its ready execution. A job is claimed for discarding the same way a worker claims it, by deleting its ready execution, so the two cannot both take it on any database (SQLite included); a job a worker claimed after the page loaded is skipped and counted as failed in the flash. Discarding a job with a concurrency limit gives back its slot and releases the next blocked job with the same key, and a ready execution whose job row is gone is simply removed. It is exposed as `POST /discard_ready_job/:id` and `POST /discard_ready_jobs`, asks for confirmation, and honours `csrf_protection_enabled`. (#45)

## [2.3.1] - 2026-10-29
Comment thread
phmunhoz marked this conversation as resolved.
Resolved

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ A lightweight, zero-dependency web interface for monitoring Solid Queue backgrou
- Complete error details with backtrace for failed jobs
- Job arguments displayed in formatted JSON
- **Queue Details Page**: Detailed view for individual queues with job counts and filtering
- **Ready Jobs**: View jobs that are ready to be executed
- **Ready Jobs**: View jobs that are ready to be executed, with the ability to discard them (e.g. jobs stranded on a queue no worker polls)
- **In Progress Jobs**: Monitor jobs currently being processed by workers
- **Scheduled Jobs**: See upcoming jobs scheduled for future execution with ability to execute immediately or reject permanently
- **Recurring Jobs**: Manage periodic jobs that run on a schedule
Expand All @@ -38,7 +38,7 @@ A lightweight, zero-dependency web interface for monitoring Solid Queue backgrou
- **Global Search**: Search across all job types by class name, queue, arguments, job ID, and error messages
- **Sortable Columns**: Click column headers to sort job tables by any column with ascending/descending toggle
- **Advanced Job Filtering**: Filter jobs by class name, queue, status, and job arguments
- **Quick Actions**: Retry or discard failed jobs, execute or reject scheduled jobs directly from any view
- **Quick Actions**: Retry or discard failed jobs, discard ready jobs, execute or reject scheduled jobs directly from any view
- **Performance Optimized**: Designed for high-volume applications with smart pagination
- **Auto-refresh**: Real-time monitoring with configurable auto-refresh interval and toggle
- **Optional Authentication**: Secure your dashboard with HTTP Basic Authentication
Expand Down Expand Up @@ -236,7 +236,7 @@ After installation, visit `/solid_queue` in your browser to access the dashboard
The dashboard provides several views:

- **Overview**: Shows statistics, recent jobs, and job activity chart
- **Ready Jobs**: Jobs that are ready to be executed
- **Ready Jobs**: Jobs that are ready to be executed, with a discard action
- **Scheduled Jobs**: Jobs scheduled for future execution with execute and reject actions
- **Recurring Jobs**: Jobs that run on a recurring schedule, with a Run now action that enqueues one task immediately without changing its schedule
- **Failed Jobs**: Jobs that have failed with error details and retry/discard actions
Expand Down
56 changes: 56 additions & 0 deletions app/assets/javascripts/solid_queue_monitor/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
initChartTooltip();
initScheduledBulkActions();
initFailedJobsBulkActions();
initReadyJobsBulkActions();
initJobDetailsBehaviors();
initGlobalBehaviors();
});
Expand Down Expand Up @@ -358,6 +359,61 @@
updateButtonState();
}

function initReadyJobsBulkActions() {
var form = document.getElementById('ready-jobs-form');
if (!form) return;

var selectAll = document.getElementById('ready-jobs-select-all');
var discardButton = document.getElementById('discard-ready-selected-top');

function checkboxes() {
return Array.prototype.slice.call(document.querySelectorAll('.ready-job-checkbox'));
}

function checkedBoxes() {
return checkboxes().filter(function (checkbox) { return checkbox.checked; });
}

function updateButtonState() {
if (discardButton) discardButton.disabled = checkedBoxes().length === 0;
}

if (selectAll) {
selectAll.addEventListener('change', function () {
checkboxes().forEach(function (checkbox) { checkbox.checked = selectAll.checked; });
updateButtonState();
});
}

checkboxes().forEach(function (checkbox) {
checkbox.addEventListener('change', function () {
if (selectAll) selectAll.checked = checkedBoxes().length === checkboxes().length;
updateButtonState();
});
});

if (discardButton) {
discardButton.addEventListener('click', function () {
var ids = checkedBoxes().map(function (checkbox) { return checkbox.value; });
if (ids.length === 0) return;
if (!window.confirm('Are you sure you want to discard the selected jobs? They will not run. This action cannot be undone.')) return;

Array.prototype.slice.call(form.querySelectorAll('input[type="hidden"][name="job_ids[]"]')).forEach(function (input) { input.remove(); });
form.action = discardButton.dataset.actionUrl;
ids.forEach(function (id) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = 'job_ids[]';
input.value = id;
form.appendChild(input);
});
form.submit();
});
}

updateButtonState();
}

function initJobDetailsBehaviors() {
document.addEventListener('click', function (e) {
var el = e.target.closest('[data-action]');
Expand Down
26 changes: 26 additions & 0 deletions app/controllers/solid_queue_monitor/ready_jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,31 @@ def index
@sort = sort_params
@action_path = ready_jobs_path
end

def discard
id = params[:id]

if SolidQueueMonitor::DiscardReadyJobService.new.call(id)
set_flash_message("Job #{id} has been discarded.", 'success')
else
set_flash_message("Failed to discard job #{id}: it is no longer ready.", 'error')
end

redirect_to ready_jobs_path
rescue StandardError => e
set_flash_message("Failed to discard job #{id}: #{e.message}", 'error')
redirect_to ready_jobs_path
end

def discard_all
result = SolidQueueMonitor::DiscardReadyJobService.new.discard_many(params[:job_ids])

if result[:success]
set_flash_message(result[:message], 'success')
else
set_flash_message(result[:message], 'error')
end
redirect_to ready_jobs_path
end
end
end
72 changes: 72 additions & 0 deletions app/services/solid_queue_monitor/discard_ready_job_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# frozen_string_literal: true

module SolidQueueMonitor
class DiscardReadyJobService
def call(id)
discard_job(id)
end

def discard_many(ids)
return { success: false, message: 'No jobs selected' } if ids.blank?

success_count = 0
failed_count = 0

Array(ids).each do |id|
if discard_job(id)
success_count += 1
else
failed_count += 1
end
rescue StandardError
failed_count += 1
end

if success_count.positive? && failed_count.zero?
{ success: true, message: 'All selected jobs have been discarded' }
elsif success_count.positive? && failed_count.positive?
{ success: true, message: "#{success_count} jobs discarded, #{failed_count} failed" }
else
{ success: false, message: 'Failed to discard jobs' }
end
end

private

# Deleting the ready execution is what claims the job, as it is for a
# worker: whoever deletes the row first wins. This holds on SQLite too,
# where the row lock is a no-op, so a job a worker already claimed counts
# as failed instead of being marked finished while it runs.
def discard_job(id)
SolidQueue::ReadyExecution.transaction do
execution = SolidQueue::ReadyExecution.lock.find_by(id: id)
next false unless execution
next false unless SolidQueue::ReadyExecution.where(id: execution.id).delete_all == 1

# An execution whose job row is gone is just removed.
job = SolidQueue::Job.find_by(id: execution.job_id)
next true unless job

release_concurrency_slot(job)
job.update!(finished_at: Time.current)
true
end
end

# A ready job holds its concurrency slot; give it back so blocked jobs
# with the same key can run. `try` because Solid Queue versions without
# concurrency controls lack these methods.
def release_concurrency_slot(job)
return unless job.try(:concurrency_limited?)

if job.class_name.safe_constantize
job.unblock_next_blocked_job
else
# The limit comes from the job class, so without it the next blocked
# job can't be released here. Free the slot by key, as Solid Queue's
# own bulk discard does; its dispatcher then unblocks waiting jobs.
SolidQueue::Job.release_all_concurrency_locks([job])
end
end
end
end
12 changes: 12 additions & 0 deletions app/views/solid_queue_monitor/ready_jobs/_row.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
<tr>
<td><input type="checkbox" class="ready-job-checkbox" value="<%= job.id %>"></td>
<td><%= link_to job.job.class_name, job_path(job.job), class: 'job-class-link' %></td>
<td><%= queue_link(job.queue_name) %></td>
<td><%= job.priority %></td>
<td><%= format_arguments(job.job.arguments) %></td>
<td><%= format_datetime(job.created_at) %></td>
<td class="actions-cell">
<div class="job-actions">
<form method="post"
action="<%= discard_ready_job_path(id: job.id) %>"
class="inline-form"
data-confirm="Are you sure you want to discard this job? It will not run.">
<%= csrf_token_field_if_enabled %>
<button type="submit" class="action-button discard-button">Discard</button>
</form>
</div>
</td>
</tr>
14 changes: 13 additions & 1 deletion app/views/solid_queue_monitor/ready_jobs/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@
filters: @filters,
show_status: false %>

<div class="bulk-actions-bar">
<button type="button" class="action-button discard-button" id="discard-ready-selected-top" data-action-url="<%= discard_ready_jobs_path %>" disabled>
Discard Selected
</button>
</div>

<form method="post" id="ready-jobs-form">
<%= csrf_token_field_if_enabled %>
</form>

<% columns = [
{ sort_key: nil, label: tag.input(type: 'checkbox', id: 'ready-jobs-select-all') },
{ sort_key: :class_name, label: 'Job' },
{ sort_key: :queue_name, label: 'Queue' },
{ sort_key: :priority, label: 'Priority' },
{ sort_key: nil, label: 'Arguments' },
{ sort_key: :created_at, label: 'Created At' }
{ sort_key: :created_at, label: 'Created At' },
{ sort_key: nil, label: 'Actions' }
] %>

<%= render 'solid_queue_monitor/shared/jobs_table',
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
resources :workers, only: [:index]
resources :jobs, only: [:show]

post 'discard_ready_job/:id', to: 'ready_jobs#discard', as: :discard_ready_job
post 'discard_ready_jobs', to: 'ready_jobs#discard_all', as: :discard_ready_jobs

post 'execute_jobs', to: 'scheduled_jobs#create', as: :execute_jobs
post 'execute_scheduled_job/:id', to: 'scheduled_jobs#execute', as: :execute_scheduled_job
post 'reject_jobs', to: 'scheduled_jobs#reject_all', as: :reject_jobs
Expand Down
77 changes: 77 additions & 0 deletions spec/requests/solid_queue_monitor/ready_jobs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,82 @@
expect(response.body).to include('priority_lane')
end
end

it 'renders the bulk discard controls with the form kept out of the table' do
get '/ready_jobs'

doc = Nokogiri::HTML5(response.body)
expect(doc.at_css('#discard-ready-selected-top')['data-action-url']).to eq('/discard_ready_jobs')
expect(doc.css('.ready-job-checkbox').map { |box| box['value'] }).to include(ready_job1.id.to_s)
expect(doc.at_css('#ready-jobs-form')).to be_present
expect(doc.at_css('#ready-jobs-form table')).to be_nil
end
end

describe 'row actions on GET /ready_jobs' do
let!(:ready_job) { create(:solid_queue_ready_execution) }

it 'submits the row Discard to its own action' do
get '/ready_jobs'

doc = Nokogiri::HTML5(response.body)
discard_form = doc.at_xpath("//button[normalize-space()='Discard']/ancestor::form[1]")

expect(discard_form['action']).to eq("/discard_ready_job/#{ready_job.id}")
end
end

describe 'POST /discard_ready_job/:id' do
let!(:ready_job) { create(:solid_queue_ready_execution) }

it 'discards the job and redirects' do
expect do
post "/discard_ready_job/#{ready_job.id}"
end.to change(SolidQueue::ReadyExecution, :count).by(-1)

expect(response).to redirect_to('/ready_jobs')
end

it 'redirects with an error instead of failing when the discard raises' do
allow_any_instance_of(SolidQueueMonitor::DiscardReadyJobService)
.to receive(:call).and_raise(ActiveRecord::LockWaitTimeout, 'lock timeout')

post "/discard_ready_job/#{ready_job.id}"

expect(response).to redirect_to('/ready_jobs')
end

it 'redirects with an error when the job is no longer ready' do
post '/discard_ready_job/999999'

expect(response).to redirect_to('/ready_jobs')
expect(SolidQueue::ReadyExecution.count).to eq(1)
end
end

describe 'POST /discard_ready_jobs' do
let!(:ready_job1) { create(:solid_queue_ready_execution) }
let!(:ready_job2) { create(:solid_queue_ready_execution) }

it 'discards the selected jobs and redirects' do
expect do
post '/discard_ready_jobs', params: { job_ids: [ready_job1.id, ready_job2.id] }
end.to change(SolidQueue::ReadyExecution, :count).by(-2)

expect(response).to redirect_to('/ready_jobs')
end

it 'accepts a single job_ids value without brackets' do
expect do
post '/discard_ready_jobs', params: { job_ids: ready_job1.id.to_s }
end.to change(SolidQueue::ReadyExecution, :count).by(-1)
end

it 'handles empty job_ids gracefully' do
post '/discard_ready_jobs', params: { job_ids: [] }

expect(response).to redirect_to('/ready_jobs')
expect(SolidQueue::ReadyExecution.count).to eq(2)
end
end
end
Loading
Loading