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, inherited, 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
33
34
35
36
37
38
39
40
41
# 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.update_result(waiting_result.id, 'cancel', 'Test cancelled by user')
    Jobs.perform(
      Jobs::ResumeTestRun,
      test_run.id,
      tags: [
        'source:delete',
        "session:#{test_run.test_session_id}",
        "run:#{test_run.test_suite_id || test_run.test_group_id || test_run.test_id}",
        "test:#{waiting_result.test_id}"
      ]
    )
  end

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