Sha256: 812a6496d825dad7d5814859ab11aecca4cf755f253bf51decc0c32a8bb3542d

Contents?: true

Size: 1.21 KB

Versions: 32

Compression:

Stored size: 1.21 KB

Contents

module Inferno
  module Web
    module Controllers
      module TestRuns
        class Destroy < Controller
          include Import[
                    test_runs_repo: 'inferno.repositories.test_runs',
                    results_repo: 'inferno.repositories.results'
                  ]

          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
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
inferno_core-0.4.27 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.26 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.25 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.24 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.23 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.22 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.21 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.20 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.19 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.18 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.17 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.16 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.15 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.14 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.13 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.12 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.11 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.10 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.9 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.4.8 lib/inferno/apps/web/controllers/test_runs/destroy.rb