Sha256: b10d6d45d6987e981f79fa94d79fd72a468dfca9315c7a12d241369495cb888b

Contents?: true

Size: 1.25 KB

Versions: 25

Compression:

Stored size: 1.25 KB

Contents

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

          def call(params)
            test_run = test_runs_repo.find(params[:id])

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

            test_run_is_waiting = (test_run.status == 'waiting')
            test_runs_repo.mark_as_cancelling(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

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

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
inferno_core-0.3.12 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.11 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.10 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.9 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.8 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.7 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.6 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.5 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.4 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.3 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.2 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.1 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.0 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.3.0.rc1 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.2.0 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.2.0.rc4 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.2.0.rc3 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.2.0.rc2 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.2.0.rc1 lib/inferno/apps/web/controllers/test_runs/destroy.rb
inferno_core-0.1.4.pre lib/inferno/apps/web/controllers/test_runs/destroy.rb