summaryrefslogtreecommitdiff
path: root/app/models/ci/running_build.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/ci/running_build.rb')
-rw-r--r--app/models/ci/running_build.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/models/ci/running_build.rb b/app/models/ci/running_build.rb
new file mode 100644
index 00000000000..9446cfa05da
--- /dev/null
+++ b/app/models/ci/running_build.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module Ci
+ class RunningBuild < ApplicationRecord
+ extend Gitlab::Ci::Model
+
+ 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