Class: Inferno::Web::Controllers::TestRuns::Destroy

Inherits:
Controller
  • Object
show all
Defined in:
lib/inferno/apps/web/controllers/test_runs/destroy.rb

Instance Method Summary collapse

Methods inherited from Controller

call, resource_class, resource_name

Instance Method Details

#handle(req, res) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/inferno/apps/web/controllers/test_runs/destroy.rb', line 11

def handle(req, res)
  test_run = test_runs_repo.find(req.params[:id])

  if test_run.nil? || ['done', 'cancelling'].include?(test_run.status)
    # If it doesn't exist, already finished, or currently being cancelled
    halt 204
  end

  test_run_is_waiting = (test_run.status == 'waiting')
  test_runs_repo.mark_as_cancelling(req.params[:id])

  if test_run_is_waiting
    waiting_result = results_repo.find_waiting_result(test_run_id: test_run.id)
    results_repo.cancel_waiting_result(waiting_result.id, 'Test cancelled by user')
    Jobs.perform(Jobs::ResumeTestRun, test_run.id)
  end

  res.status = 204
rescue StandardError => e
  Application['logger'].error(e.full_message)
  halt 500, { errors: e.message }.to_json
end