summaryrefslogtreecommitdiff
path: root/app/models/ci/running_build.rb
blob: ae38d54862d9020a93f01aea44d79b4be5426e6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module Ci
  class RunningBuild < Ci::ApplicationRecord
    belongs_to :project
    belongs_to :build, class_name: 'Ci::Build'
    belongs_to :runner, class_name: 'Ci::Runner'

    enum runner_type: ::Ci::Runner.runner_types

    def self.upsert_shared_runner_build!(build)
      unless build.shared_runner_build?
        raise ArgumentError, 'build has not been picked by a shared runner'
      end

      entry = self.new(build: build,
                       project: build.project,
                       runner: build.runner,
                       runner_type: build.runner.runner_type)

      entry.validate!

      self.upsert(entry.attributes.compact, returning: %w[build_id], unique_by: :build_id)
    end
  end
end