Class: Ci::RunningBuild

Inherits:
ApplicationRecord show all
Includes:
Partitionable
Defined in:
app/models/ci/running_build.rb

Overview

This model represents metadata for a running build.

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Methods included from Partitionable

registered_models

Methods inherited from ApplicationRecord

model_name, table_name_prefix

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.upsert_build!(build) ⇒ Object

Raises:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/ci/running_build.rb', line 19

def self.upsert_build!(build)
  raise ArgumentError, 'build has not been picked by a runner' if build.runner.nil?

  # Owner namespace of the runner that executed the build
  runner_owner_namespace_id = build.runner.owner_runner_namespace.namespace_id if build.runner.group_type?

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

  entry.validate!

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