Skip to content

Commit

Permalink
Merge pull request #4855 from yrudman/rescue-error-when-canceling-job
Browse files Browse the repository at this point in the history
Rescue error when canceling job

(cherry picked from commit bccb10e)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1640704
  • Loading branch information
h-kataria authored and simaishi committed Oct 31, 2018
1 parent 19322da commit 5646ad4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/miq_task_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def cancel_task
elsif task.state.downcase == "finished"
_("Finished Task cannot be cancelled")
else
task.process_cancel
begin
task.process_cancel
rescue RuntimeError => e
e.message
end
end
add_flash(message, :error)
jobs
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/miq_task_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,22 @@
end
end

describe ".cancel_task" do
before do
allow(controller).to receive(:jobs_info)
allow(controller).to receive(:role_allows?).and_return(true)

task = double("MiqTask")
allow(MiqTask).to receive(:find_by).and_return(task)
allow(task).to receive(:state).and_return("starting")
allow(task).to receive(:process_cancel).and_raise("Not Permitted Signal")
end

it "does not raise error if not alowed signal sent" do
expect { controller.cancel_task }.not_to raise_error
end
end

def get_time_period(period)
t = format_timezone(period.to_i != 0 ? period.days.ago : Time.now, Time.zone, "raw")
ret = []
Expand Down

0 comments on commit 5646ad4

Please sign in to comment.