Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow resuming errored task runs #854

Merged
merged 1 commit into from
Jan 2, 2024
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
3 changes: 3 additions & 0 deletions app/validators/maintenance_tasks/run_status_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class RunStatusValidator < ActiveModel::Validator
# interrupted -> errored occurs when the task is deleted while it is
# interrupted.
"interrupted" => ["running", "pausing", "cancelling", "errored"],
# errored -> enqueued occurs when the task is retried after encounting an
# error.
"errored" => ["enqueued"],
}

# Validate whether a transition from one Run status
Expand Down
2 changes: 2 additions & 0 deletions app/views/maintenance_tasks/runs/_run.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<% if run.paused? %>
<%= button_to 'Resume', resume_task_run_path(@task, run), method: :put, class: 'button is-primary', disabled: @task.deleted? %>
<%= button_to 'Cancel', cancel_task_run_path(@task, run), method: :put, class: 'button is-danger' %>
<% elsif run.errored? %>
<%= button_to 'Resume', resume_task_run_path(@task, run), method: :put, class: 'button is-primary', disabled: @task.deleted? %>
<% elsif run.cancelling? %>
<% if run.stuck? %>
<%= button_to 'Cancel', cancel_task_run_path(@task, run), method: :put, class: 'button is-danger', disabled: @task.deleted? %>
Expand Down
5 changes: 5 additions & 0 deletions test/system/maintenance_tasks/runs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ class RunsTest < ApplicationSystemTestCase
assert_text "ArgumentError"
assert_text "Something went wrong"
assert_text "app/tasks/maintenance/error_task.rb:10:in `process'"

click_on "Resume"

assert_text "Enqueued"
assert_text "Waiting to start."
end

test "errors for double enqueue are shown" do
Expand Down
12 changes: 10 additions & 2 deletions test/validators/maintenance_tasks/run_status_validator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RunStatusValidatorTest < ActiveSupport::TestCase
assert_no_invalid_transitions([:enqueued, :interrupted], :running)
end

test "run can go from paused to enqueued" do
test "run can go from paused or errored to enqueued" do
paused_run = Run.create!(
task_name: "Maintenance::UpdatePostsTask",
status: :paused,
Expand All @@ -30,7 +30,15 @@ class RunStatusValidatorTest < ActiveSupport::TestCase

assert paused_run.valid?

assert_no_invalid_transitions([:paused], :enqueued)
errored_run = Run.create!(
task_name: "Maintenance::UpdatePostsTask",
status: :errored,
)
errored_run.status = :enqueued

assert errored_run.valid?

assert_no_invalid_transitions([:paused, :errored], :enqueued)
end

test "run can go from running, cancelling or pausing to succeeded" do
Expand Down