Skip to content

Commit

Permalink
Add resume run action to RunsController (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
promulo authored Jul 7, 2022
1 parent 40fdef2 commit 9c90a92
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/controllers/maintenance_tasks/runs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def cancel
redirect_to(task_path(@run.task_name), alert: error.message)
end

# Resumes a previously paused Run.
def resume
Runner.run(name: @run.task_name)
redirect_to(task_path(@run.task_name))
rescue ActiveRecord::RecordInvalid => error
redirect_to(task_path(@run.task_name), alert: error.message)
rescue Runner::EnqueuingError => error
redirect_to(task_path(@run.task_name), alert: error.message)
end

private

def set_run
Expand Down
2 changes: 1 addition & 1 deletion app/views/maintenance_tasks/tasks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<%= button_to 'Pausing', pause_task_run_path(@task, last_run), method: :put, class: 'button is-warning', disabled: true %>
<%= button_to 'Cancel', cancel_task_run_path(@task, last_run), method: :put, class: 'button is-danger' %>
<% elsif last_run.paused? %>
<%= button_to 'Resume', run_task_path(@task), method: :put, class: 'button is-primary', disabled: @task.deleted? %>
<%= button_to 'Resume', resume_task_run_path(@task, last_run), method: :put, class: 'button is-primary', disabled: @task.deleted? %>
<%= button_to 'Cancel', cancel_task_run_path(@task, last_run), method: :put, class: 'button is-danger' %>
<% else %>
<%= button_to 'Pause', pause_task_run_path(@task, last_run), method: :put, class: 'button is-warning', disabled: @task.deleted? %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
member do
put "pause"
put "cancel"
put "resume"
end
end
end
Expand Down

0 comments on commit 9c90a92

Please sign in to comment.