Skip to content

Commit

Permalink
Adds a "Discard all" button to queue show page, if there are enqueued…
Browse files Browse the repository at this point in the history
… jobs
  • Loading branch information
matthewbjones committed Dec 3, 2024
1 parent 217f344 commit 4230a96
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class MissionControl::Jobs::Queues::DiscardsController < MissionControl::Jobs::ApplicationController
include MissionControl::Jobs::QueueScoped

def create
@queue.clear

redirect_to application_queues_url(@application)
end
end
3 changes: 3 additions & 0 deletions app/views/mission_control/jobs/queues/_actions.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div class="buttons is-right">
<% if queue.size.positive? %>
<%= button_to "Discard all", application_queue_discard_path(@application, queue.name), method: :post, class: "button is-danger is-light mr-0", form: { data: { turbo_confirm: "This will delete #{queue.size} pending jobs in the queue and can't be undone. Are you sure?" } } %>
<% end %>
<% if queue.active? %>
<%= button_to "Pause", application_queue_pause_path(@application, queue.name), method: :post, class: "button is-success is-light mr-0" %>
<% else %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resources :applications, only: [] do
resources :queues, only: [ :index, :show ] do
scope module: :queues do
resource :discard, only: :create
resource :pause, only: [ :create, :destroy ]
end
end
Expand Down
20 changes: 20 additions & 0 deletions test/system/discard_queue_jobs_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require_relative "../application_system_test_case"

class DiscardQueueJobsTest < ApplicationSystemTestCase
setup do
DummyJob.queue_as :queue_1
10.times { |index| DummyJob.perform_later("dummy-arg-#{index}") }

visit queues_path
end

test "discard all jobs" do
click_on "queue_1"

assert_equal 10, job_row_elements.length

accept_confirm do
click_on "Discard all"
end
end
end

0 comments on commit 4230a96

Please sign in to comment.