Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/ci')
-rw-r--r--app/models/ci/application_record.rb15
-rw-r--r--app/models/ci/build.rb31
-rw-r--r--app/models/ci/build_metadata.rb3
-rw-r--r--app/models/ci/build_need.rb4
-rw-r--r--app/models/ci/build_pending_state.rb4
-rw-r--r--app/models/ci/build_report_result.rb4
-rw-r--r--app/models/ci/build_runner_session.rb3
-rw-r--r--app/models/ci/build_trace_chunk.rb3
-rw-r--r--app/models/ci/build_trace_metadata.rb13
-rw-r--r--app/models/ci/build_trace_section.rb17
-rw-r--r--app/models/ci/build_trace_section_name.rb13
-rw-r--r--app/models/ci/ci_database_record.rb (renamed from app/models/ci/base_model.rb)2
-rw-r--r--app/models/ci/daily_build_group_report_result.rb4
-rw-r--r--app/models/ci/deleted_object.rb4
-rw-r--r--app/models/ci/freeze_period.rb6
-rw-r--r--app/models/ci/group_variable.rb3
-rw-r--r--app/models/ci/instance_variable.rb3
-rw-r--r--app/models/ci/job_artifact.rb3
-rw-r--r--app/models/ci/job_variable.rb3
-rw-r--r--app/models/ci/pending_build.rb13
-rw-r--r--app/models/ci/pipeline.rb20
-rw-r--r--app/models/ci/pipeline_artifact.rb3
-rw-r--r--app/models/ci/pipeline_chat_data.rb4
-rw-r--r--app/models/ci/pipeline_config.rb4
-rw-r--r--app/models/ci/pipeline_message.rb4
-rw-r--r--app/models/ci/pipeline_schedule.rb5
-rw-r--r--app/models/ci/pipeline_schedule_variable.rb3
-rw-r--r--app/models/ci/pipeline_variable.rb3
-rw-r--r--app/models/ci/processable.rb6
-rw-r--r--app/models/ci/ref.rb3
-rw-r--r--app/models/ci/resource.rb19
-rw-r--r--app/models/ci/resource_group.rb4
-rw-r--r--app/models/ci/runner.rb12
-rw-r--r--app/models/ci/runner_namespace.rb4
-rw-r--r--app/models/ci/runner_project.rb4
-rw-r--r--app/models/ci/running_build.rb4
-rw-r--r--app/models/ci/sources/pipeline.rb4
-rw-r--r--app/models/ci/stage.rb3
-rw-r--r--app/models/ci/trigger.rb3
-rw-r--r--app/models/ci/trigger_request.rb4
-rw-r--r--app/models/ci/unit_test.rb4
-rw-r--r--app/models/ci/unit_test_failure.rb4
-rw-r--r--app/models/ci/variable.rb3
43 files changed, 123 insertions, 155 deletions
diff --git a/app/models/ci/application_record.rb b/app/models/ci/application_record.rb
new file mode 100644
index 00000000000..9d4a8f0648e
--- /dev/null
+++ b/app/models/ci/application_record.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module Ci
+ class ApplicationRecord < ::ApplicationRecord
+ self.abstract_class = true
+
+ def self.table_name_prefix
+ 'ci_'
+ end
+
+ def self.model_name
+ @model_name ||= ActiveModel::Name.new(self, nil, self.name.demodulize)
+ end
+ end
+end
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 4328f3f7a4b..1ca291a659b 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -39,7 +39,6 @@ module Ci
has_one :pending_state, class_name: 'Ci::BuildPendingState', inverse_of: :build
has_one :queuing_entry, class_name: 'Ci::PendingBuild', foreign_key: :build_id
has_one :runtime_metadata, class_name: 'Ci::RunningBuild', foreign_key: :build_id
- has_many :trace_sections, class_name: 'Ci::BuildTraceSection'
has_many :trace_chunks, class_name: 'Ci::BuildTraceChunk', foreign_key: :build_id, inverse_of: :build
has_many :report_results, class_name: 'Ci::BuildReportResult', inverse_of: :build
@@ -54,6 +53,7 @@ module Ci
end
has_one :runner_session, class_name: 'Ci::BuildRunnerSession', validate: true, inverse_of: :build
+ has_one :trace_metadata, class_name: 'Ci::BuildTraceMetadata', inverse_of: :build
accepts_nested_attributes_for :runner_session, update_only: true
accepts_nested_attributes_for :job_variables
@@ -103,7 +103,6 @@ module Ci
end
scope :unstarted, -> { where(runner_id: nil) }
- scope :ignore_failures, -> { where(allow_failure: false) }
scope :with_downloadable_artifacts, -> do
where('EXISTS (?)',
Ci::JobArtifact.select(1)
@@ -120,10 +119,6 @@ module Ci
where('EXISTS (?)', ::Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id').merge(query))
end
- scope :with_archived_trace, -> do
- with_existing_job_artifacts(Ci::JobArtifact.trace)
- end
-
scope :without_archived_trace, -> do
where('NOT EXISTS (?)', Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id').trace)
end
@@ -134,7 +129,6 @@ module Ci
end
scope :eager_load_job_artifacts, -> { includes(:job_artifacts) }
- scope :eager_load_job_artifacts_archive, -> { includes(:job_artifacts_archive) }
scope :eager_load_tags, -> { includes(:tags) }
scope :eager_load_everything, -> do
@@ -158,7 +152,7 @@ module Ci
scope :with_project_and_metadata, -> do
if Feature.enabled?(:non_public_artifacts, type: :development)
- joins(:metadata).includes(:project, :metadata)
+ joins(:metadata).includes(:metadata).preload(:project)
end
end
@@ -466,13 +460,9 @@ module Ci
end
def retryable?
- if Feature.enabled?(:prevent_retry_of_retried_jobs, project, default_enabled: :yaml)
- return false if retried? || archived?
+ return false if retried? || archived?
- success? || failed? || canceled?
- else
- !archived? && (success? || failed? || canceled?)
- end
+ success? || failed? || canceled?
end
def retries_count
@@ -559,6 +549,7 @@ module Ci
.concat(persisted_variables)
.concat(dependency_proxy_variables)
.concat(job_jwt_variables)
+ .concat(kubernetes_variables)
.concat(scoped_variables)
.concat(job_variables)
.concat(persisted_environment_variables)
@@ -648,12 +639,6 @@ module Ci
update(coverage: coverage) if coverage.present?
end
- # rubocop: disable CodeReuse/ServiceClass
- def parse_trace_sections!
- ExtractSectionsFromBuildTraceService.new(project, user).execute(self)
- end
- # rubocop: enable CodeReuse/ServiceClass
-
def trace
Gitlab::Ci::Trace.new(self)
end
@@ -907,7 +892,7 @@ module Ci
end
def valid_dependency?
- return false if artifacts_expired?
+ return false if artifacts_expired? && !pipeline.artifacts_locked?
return false if erased?
true
@@ -1183,6 +1168,10 @@ module Ci
end
end
+ def kubernetes_variables
+ [] # Overridden in EE
+ end
+
def conditionally_allow_failure!(exit_code)
return unless exit_code
diff --git a/app/models/ci/build_metadata.rb b/app/models/ci/build_metadata.rb
index 50775f578f0..90237a4be52 100644
--- a/app/models/ci/build_metadata.rb
+++ b/app/models/ci/build_metadata.rb
@@ -3,10 +3,9 @@
module Ci
# The purpose of this class is to store Build related data that can be disposed.
# Data that should be persisted forever, should be stored with Ci::Build model.
- class BuildMetadata < ApplicationRecord
+ class BuildMetadata < Ci::ApplicationRecord
BuildTimeout = Struct.new(:value, :source)
- extend Gitlab::Ci::Model
include Presentable
include ChronicDurationAttribute
include Gitlab::Utils::StrongMemoize
diff --git a/app/models/ci/build_need.rb b/app/models/ci/build_need.rb
index 4a59c25cbb0..003659570b3 100644
--- a/app/models/ci/build_need.rb
+++ b/app/models/ci/build_need.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
module Ci
- class BuildNeed < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class BuildNeed < Ci::ApplicationRecord
include BulkInsertSafe
include IgnorableColumns
diff --git a/app/models/ci/build_pending_state.rb b/app/models/ci/build_pending_state.rb
index 299c67f441d..53cf0697e2e 100644
--- a/app/models/ci/build_pending_state.rb
+++ b/app/models/ci/build_pending_state.rb
@@ -1,8 +1,6 @@
# frozen_string_literal: true
-class Ci::BuildPendingState < ApplicationRecord
- extend Gitlab::Ci::Model
-
+class Ci::BuildPendingState < Ci::ApplicationRecord
belongs_to :build, class_name: 'Ci::Build', foreign_key: :build_id
enum state: Ci::Stage.statuses
diff --git a/app/models/ci/build_report_result.rb b/app/models/ci/build_report_result.rb
index eb6a0700006..2c08fc4c8bf 100644
--- a/app/models/ci/build_report_result.rb
+++ b/app/models/ci/build_report_result.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
module Ci
- class BuildReportResult < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class BuildReportResult < Ci::ApplicationRecord
self.primary_key = :build_id
belongs_to :build, class_name: "Ci::Build", inverse_of: :report_results
diff --git a/app/models/ci/build_runner_session.rb b/app/models/ci/build_runner_session.rb
index 2aa856dbc64..45de47116cd 100644
--- a/app/models/ci/build_runner_session.rb
+++ b/app/models/ci/build_runner_session.rb
@@ -3,8 +3,7 @@
module Ci
# The purpose of this class is to store Build related runner session.
# Data will be removed after transitioning from running to any state.
- class BuildRunnerSession < ApplicationRecord
- extend Gitlab::Ci::Model
+ class BuildRunnerSession < Ci::ApplicationRecord
include IgnorableColumns
ignore_columns :build_id_convert_to_bigint, remove_with: '14.1', remove_after: '2021-07-22'
diff --git a/app/models/ci/build_trace_chunk.rb b/app/models/ci/build_trace_chunk.rb
index 3fa9a484b0c..7a15d7ba940 100644
--- a/app/models/ci/build_trace_chunk.rb
+++ b/app/models/ci/build_trace_chunk.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class BuildTraceChunk < ApplicationRecord
- extend ::Gitlab::Ci::Model
+ class BuildTraceChunk < Ci::ApplicationRecord
include ::Comparable
include ::FastDestroyAll
include ::Checksummable
diff --git a/app/models/ci/build_trace_metadata.rb b/app/models/ci/build_trace_metadata.rb
new file mode 100644
index 00000000000..05bdb3d8b7b
--- /dev/null
+++ b/app/models/ci/build_trace_metadata.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+module Ci
+ class BuildTraceMetadata < Ci::ApplicationRecord
+ self.table_name = 'ci_build_trace_metadata'
+ self.primary_key = :build_id
+
+ belongs_to :build, class_name: 'Ci::Build'
+ belongs_to :trace_artifact, class_name: 'Ci::JobArtifact'
+
+ validates :build, presence: true
+ end
+end
diff --git a/app/models/ci/build_trace_section.rb b/app/models/ci/build_trace_section.rb
deleted file mode 100644
index 036f611a61c..00000000000
--- a/app/models/ci/build_trace_section.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-module Ci
- class BuildTraceSection < ApplicationRecord
- extend SuppressCompositePrimaryKeyWarning
- extend Gitlab::Ci::Model
- include IgnorableColumns
-
- belongs_to :build, class_name: 'Ci::Build'
- belongs_to :project
- belongs_to :section_name, class_name: 'Ci::BuildTraceSectionName'
-
- validates :section_name, :build, :project, presence: true, allow_blank: false
-
- ignore_column :build_id_convert_to_bigint, remove_with: '14.2', remove_after: '2021-08-22'
- end
-end
diff --git a/app/models/ci/build_trace_section_name.rb b/app/models/ci/build_trace_section_name.rb
deleted file mode 100644
index c065cfea14e..00000000000
--- a/app/models/ci/build_trace_section_name.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-module Ci
- class BuildTraceSectionName < ApplicationRecord
- extend Gitlab::Ci::Model
-
- belongs_to :project
- has_many :trace_sections, class_name: 'Ci::BuildTraceSection', foreign_key: :section_name_id
-
- validates :name, :project, presence: true, allow_blank: false
- validates :name, uniqueness: { scope: :project_id }
- end
-end
diff --git a/app/models/ci/base_model.rb b/app/models/ci/ci_database_record.rb
index 8fb752ead1d..e2b832a28e7 100644
--- a/app/models/ci/base_model.rb
+++ b/app/models/ci/ci_database_record.rb
@@ -7,7 +7,7 @@ module Ci
# This class is part of a migration to move all CI classes to a new separate database.
# Initially we are only going to be moving the `Ci::InstanceVariable` model and it will be duplicated in the main and CI tables
# Do not extend this class in any other models.
- class BaseModel < ::ApplicationRecord
+ class CiDatabaseRecord < Ci::ApplicationRecord
self.abstract_class = true
if Gitlab::Database.has_config?(:ci)
diff --git a/app/models/ci/daily_build_group_report_result.rb b/app/models/ci/daily_build_group_report_result.rb
index b46d32474c6..598d1456a48 100644
--- a/app/models/ci/daily_build_group_report_result.rb
+++ b/app/models/ci/daily_build_group_report_result.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
module Ci
- class DailyBuildGroupReportResult < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class DailyBuildGroupReportResult < Ci::ApplicationRecord
PARAM_TYPES = %w[coverage].freeze
belongs_to :last_pipeline, class_name: 'Ci::Pipeline', foreign_key: :last_pipeline_id
diff --git a/app/models/ci/deleted_object.rb b/app/models/ci/deleted_object.rb
index b2a949c9bb5..aba7b73aba9 100644
--- a/app/models/ci/deleted_object.rb
+++ b/app/models/ci/deleted_object.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
module Ci
- class DeletedObject < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class DeletedObject < Ci::ApplicationRecord
mount_uploader :file, DeletedObjectUploader
scope :ready_for_destruction, ->(limit) do
diff --git a/app/models/ci/freeze_period.rb b/app/models/ci/freeze_period.rb
index d215372bb45..da0bbbacddd 100644
--- a/app/models/ci/freeze_period.rb
+++ b/app/models/ci/freeze_period.rb
@@ -1,15 +1,15 @@
# frozen_string_literal: true
module Ci
- class FreezePeriod < ApplicationRecord
+ class FreezePeriod < Ci::ApplicationRecord
include StripAttribute
- self.table_name = 'ci_freeze_periods'
+ include Ci::NamespacedModelName
default_scope { order(created_at: :asc) } # rubocop:disable Cop/DefaultScope
belongs_to :project, inverse_of: :freeze_periods
- strip_attributes :freeze_start, :freeze_end
+ strip_attributes! :freeze_start, :freeze_end
validates :freeze_start, cron: true, presence: true
validates :freeze_end, cron: true, presence: true
diff --git a/app/models/ci/group_variable.rb b/app/models/ci/group_variable.rb
index 2928ce801ad..165bee5c54d 100644
--- a/app/models/ci/group_variable.rb
+++ b/app/models/ci/group_variable.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class GroupVariable < ApplicationRecord
- extend Gitlab::Ci::Model
+ class GroupVariable < Ci::ApplicationRecord
include Ci::HasVariable
include Presentable
include Ci::Maskable
diff --git a/app/models/ci/instance_variable.rb b/app/models/ci/instance_variable.rb
index 5aee4c924af..f4aa935b983 100644
--- a/app/models/ci/instance_variable.rb
+++ b/app/models/ci/instance_variable.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class InstanceVariable < ::Ci::BaseModel
- extend Gitlab::Ci::Model
+ class InstanceVariable < Ci::CiDatabaseRecord
extend Gitlab::ProcessMemoryCache::Helper
include Ci::NewHasVariable
include Ci::Maskable
diff --git a/app/models/ci/job_artifact.rb b/app/models/ci/job_artifact.rb
index 46c976d5616..1f0da4345f2 100644
--- a/app/models/ci/job_artifact.rb
+++ b/app/models/ci/job_artifact.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Ci
- class JobArtifact < ApplicationRecord
+ class JobArtifact < Ci::ApplicationRecord
include AfterCommitQueue
include ObjectStorage::BackgroundMove
include UpdateProjectStatistics
@@ -10,7 +10,6 @@ module Ci
include Artifactable
include FileStoreMounter
include EachBatch
- extend Gitlab::Ci::Model
TEST_REPORT_FILE_TYPES = %w[junit].freeze
COVERAGE_REPORT_FILE_TYPES = %w[cobertura].freeze
diff --git a/app/models/ci/job_variable.rb b/app/models/ci/job_variable.rb
index 7eea8a37150..44bd3fe8901 100644
--- a/app/models/ci/job_variable.rb
+++ b/app/models/ci/job_variable.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class JobVariable < ApplicationRecord
- extend Gitlab::Ci::Model
+ class JobVariable < Ci::ApplicationRecord
include Ci::NewHasVariable
include BulkInsertSafe
diff --git a/app/models/ci/pending_build.rb b/app/models/ci/pending_build.rb
index 0663052f51d..7cf3a387516 100644
--- a/app/models/ci/pending_build.rb
+++ b/app/models/ci/pending_build.rb
@@ -1,14 +1,16 @@
# frozen_string_literal: true
module Ci
- class PendingBuild < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class PendingBuild < Ci::ApplicationRecord
belongs_to :project
belongs_to :build, class_name: 'Ci::Build'
+ belongs_to :namespace, inverse_of: :pending_builds, class_name: 'Namespace'
+
+ validates :namespace, presence: true
scope :ref_protected, -> { where(protected: true) }
scope :queued_before, ->(time) { where(arel_table[:created_at].lt(time)) }
+ scope :with_instance_runners, -> { where(instance_runners_enabled: true) }
def self.upsert_from_build!(build)
entry = self.new(args_from_build(build))
@@ -22,7 +24,8 @@ module Ci
args = {
build: build,
project: build.project,
- protected: build.protected?
+ protected: build.protected?,
+ namespace: build.project.namespace
}
if Feature.enabled?(:ci_pending_builds_maintain_shared_runners_data, type: :development, default_enabled: :yaml)
@@ -56,3 +59,5 @@ module Ci
private_class_method :builds_access_level?
end
end
+
+Ci::PendingBuild.prepend_mod_with('Ci::PendingBuild')
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 5d079f57267..70e67953e31 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class Pipeline < ApplicationRecord
- extend Gitlab::Ci::Model
+ class Pipeline < Ci::ApplicationRecord
include Ci::HasStatus
include Importable
include AfterCommitQueue
@@ -319,6 +318,7 @@ module Ci
scope :created_before_id, -> (id) { where('ci_pipelines.id < ?', id) }
scope :before_pipeline, -> (pipeline) { created_before_id(pipeline.id).outside_pipeline_family(pipeline) }
scope :eager_load_project, -> { eager_load(project: [:route, { namespace: :route }]) }
+ scope :with_pipeline_source, -> (source) { where(source: source)}
scope :outside_pipeline_family, ->(pipeline) do
where.not(id: pipeline.same_family_pipeline_ids)
@@ -378,11 +378,15 @@ module Ci
end
def self.latest_successful_for_refs(refs)
- relation = newest_first(ref: refs).success
+ return Ci::Pipeline.none if refs.empty?
- relation.each_with_object({}) do |pipeline, hash|
- hash[pipeline.ref] ||= pipeline
- end
+ refs_values = refs.map { |ref| "(#{connection.quote(ref)})" }.join(",")
+ join_query = success.where("refs_values.ref = ci_pipelines.ref").order(id: :desc).limit(1)
+
+ Ci::Pipeline
+ .from("(VALUES #{refs_values}) refs_values (ref)")
+ .joins("INNER JOIN LATERAL (#{join_query.to_sql}) #{Ci::Pipeline.table_name} ON TRUE")
+ .index_by(&:ref)
end
def self.latest_running_for_ref(ref)
@@ -393,6 +397,10 @@ module Ci
newest_first(ref: ref).failed.take
end
+ def self.jobs_count_in_alive_pipelines
+ created_after(24.hours.ago).alive.joins(:builds).count
+ end
+
# Returns a Hash containing the latest pipeline for every given
# commit.
#
diff --git a/app/models/ci/pipeline_artifact.rb b/app/models/ci/pipeline_artifact.rb
index 889c5d094a7..2284a05bcc9 100644
--- a/app/models/ci/pipeline_artifact.rb
+++ b/app/models/ci/pipeline_artifact.rb
@@ -3,8 +3,7 @@
# This class is being used to persist additional artifacts after a pipeline completes, which is a great place to cache a computed result in object storage
module Ci
- class PipelineArtifact < ApplicationRecord
- extend Gitlab::Ci::Model
+ class PipelineArtifact < Ci::ApplicationRecord
include UpdateProjectStatistics
include Artifactable
include FileStoreMounter
diff --git a/app/models/ci/pipeline_chat_data.rb b/app/models/ci/pipeline_chat_data.rb
index 65466a8c6f8..ba20c993e36 100644
--- a/app/models/ci/pipeline_chat_data.rb
+++ b/app/models/ci/pipeline_chat_data.rb
@@ -1,7 +1,9 @@
# frozen_string_literal: true
module Ci
- class PipelineChatData < ApplicationRecord
+ class PipelineChatData < Ci::ApplicationRecord
+ include Ci::NamespacedModelName
+
self.table_name = 'ci_pipeline_chat_data'
belongs_to :chat_name
diff --git a/app/models/ci/pipeline_config.rb b/app/models/ci/pipeline_config.rb
index d5a8da2bc1e..e2dcad653d7 100644
--- a/app/models/ci/pipeline_config.rb
+++ b/app/models/ci/pipeline_config.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
module Ci
- class PipelineConfig < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class PipelineConfig < Ci::ApplicationRecord
self.table_name = 'ci_pipelines_config'
self.primary_key = :pipeline_id
diff --git a/app/models/ci/pipeline_message.rb b/app/models/ci/pipeline_message.rb
index a47ec554462..5668da915e6 100644
--- a/app/models/ci/pipeline_message.rb
+++ b/app/models/ci/pipeline_message.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
module Ci
- class PipelineMessage < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class PipelineMessage < Ci::ApplicationRecord
MAX_CONTENT_LENGTH = 10_000
belongs_to :pipeline
diff --git a/app/models/ci/pipeline_schedule.rb b/app/models/ci/pipeline_schedule.rb
index effe2d95a99..b915495ac38 100644
--- a/app/models/ci/pipeline_schedule.rb
+++ b/app/models/ci/pipeline_schedule.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class PipelineSchedule < ApplicationRecord
- extend Gitlab::Ci::Model
+ class PipelineSchedule < Ci::ApplicationRecord
extend ::Gitlab::Utils::Override
include Importable
include StripAttribute
@@ -25,7 +24,7 @@ module Ci
validates :description, presence: true
validates :variables, nested_attributes_duplicates: true
- strip_attributes :cron
+ strip_attributes! :cron
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
diff --git a/app/models/ci/pipeline_schedule_variable.rb b/app/models/ci/pipeline_schedule_variable.rb
index adef9911ae1..84a24609cc7 100644
--- a/app/models/ci/pipeline_schedule_variable.rb
+++ b/app/models/ci/pipeline_schedule_variable.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class PipelineScheduleVariable < ApplicationRecord
- extend Gitlab::Ci::Model
+ class PipelineScheduleVariable < Ci::ApplicationRecord
include Ci::HasVariable
belongs_to :pipeline_schedule
diff --git a/app/models/ci/pipeline_variable.rb b/app/models/ci/pipeline_variable.rb
index 84ca4833cd7..a0e8886414b 100644
--- a/app/models/ci/pipeline_variable.rb
+++ b/app/models/ci/pipeline_variable.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class PipelineVariable < ApplicationRecord
- extend Gitlab::Ci::Model
+ class PipelineVariable < Ci::ApplicationRecord
include Ci::HasVariable
belongs_to :pipeline
diff --git a/app/models/ci/processable.rb b/app/models/ci/processable.rb
index e2f257eab25..30d335fd7d5 100644
--- a/app/models/ci/processable.rb
+++ b/app/models/ci/processable.rb
@@ -169,11 +169,7 @@ module Ci
end
def all_dependencies
- if Feature.enabled?(:preload_associations_jobs_request_api_endpoint, project, default_enabled: :yaml)
- strong_memoize(:all_dependencies) do
- dependencies.all
- end
- else
+ strong_memoize(:all_dependencies) do
dependencies.all
end
end
diff --git a/app/models/ci/ref.rb b/app/models/ci/ref.rb
index 3d71a5f2c96..af5fdabff6e 100644
--- a/app/models/ci/ref.rb
+++ b/app/models/ci/ref.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class Ref < ApplicationRecord
- extend Gitlab::Ci::Model
+ class Ref < Ci::ApplicationRecord
include AfterCommitQueue
include Gitlab::OptimisticLocking
diff --git a/app/models/ci/resource.rb b/app/models/ci/resource.rb
index e0e1fab642d..ee094fa2007 100644
--- a/app/models/ci/resource.rb
+++ b/app/models/ci/resource.rb
@@ -1,13 +1,26 @@
# frozen_string_literal: true
module Ci
- class Resource < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class Resource < Ci::ApplicationRecord
belongs_to :resource_group, class_name: 'Ci::ResourceGroup', inverse_of: :resources
belongs_to :processable, class_name: 'Ci::Processable', foreign_key: 'build_id', inverse_of: :resource
scope :free, -> { where(processable: nil) }
+ scope :retained, -> { where.not(processable: nil) }
scope :retained_by, -> (processable) { where(processable: processable) }
+
+ class << self
+ # In some cases, state machine hooks in `Ci::Build` are skipped
+ # even if the job status transitions to a complete state.
+ # For example, `Ci::Build#doom!` (a.k.a `data_integrity_failure`) doesn't execute state machine hooks.
+ # To handle these edge cases, we check the staleness of the jobs that currently
+ # assigned to the resources, and release if it's stale.
+ # See https://gitlab.com/gitlab-org/gitlab/-/issues/335537#note_632925914 for more information.
+ def stale_processables
+ Ci::Processable.where(id: retained.select(:build_id))
+ .complete
+ .updated_at_before(5.minutes.ago)
+ end
+ end
end
end
diff --git a/app/models/ci/resource_group.rb b/app/models/ci/resource_group.rb
index 85fbe03e1c9..8a7456041e6 100644
--- a/app/models/ci/resource_group.rb
+++ b/app/models/ci/resource_group.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
module Ci
- class ResourceGroup < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class ResourceGroup < Ci::ApplicationRecord
belongs_to :project, inverse_of: :resource_groups
has_many :resources, class_name: 'Ci::Resource', inverse_of: :resource_group
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index a541dca47de..432c3a408a9 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class Runner < ApplicationRecord
- extend Gitlab::Ci::Model
+ class Runner < Ci::ApplicationRecord
include Gitlab::SQL::Pattern
include RedisCacheable
include ChronicDurationAttribute
@@ -12,6 +11,7 @@ module Ci
include FeatureGate
include Gitlab::Utils::StrongMemoize
include TaggableQueries
+ include Presentable
add_authentication_token_field :token, encrypted: :optional
@@ -61,13 +61,7 @@ module Ci
scope :paused, -> { where(active: false) }
scope :online, -> { where('contacted_at > ?', online_contact_time_deadline) }
scope :recent, -> { where('ci_runners.created_at > :date OR ci_runners.contacted_at > :date', date: 3.months.ago) }
- # The following query using negation is cheaper than using `contacted_at <= ?`
- # because there are less runners online than have been created. The
- # resulting query is quickly finding online ones and then uses the regular
- # indexed search and rejects the ones that are in the previous set. If we
- # did `contacted_at <= ?` the query would effectively have to do a seq
- # scan.
- scope :offline, -> { where.not(id: online) }
+ scope :offline, -> { where(arel_table[:contacted_at].lteq(online_contact_time_deadline)) }
scope :not_connected, -> { where(contacted_at: nil) }
scope :ordered, -> { order(id: :desc) }
diff --git a/app/models/ci/runner_namespace.rb b/app/models/ci/runner_namespace.rb
index 41a4c9012ff..d1353b97ed9 100644
--- a/app/models/ci/runner_namespace.rb
+++ b/app/models/ci/runner_namespace.rb
@@ -1,14 +1,14 @@
# frozen_string_literal: true
module Ci
- class RunnerNamespace < ApplicationRecord
- extend Gitlab::Ci::Model
+ class RunnerNamespace < Ci::ApplicationRecord
include Limitable
self.limit_name = 'ci_registered_group_runners'
self.limit_scope = :group
self.limit_relation = :recent_runners
self.limit_feature_flag = :ci_runner_limits
+ self.limit_feature_flag_for_override = :ci_runner_limits_override
belongs_to :runner, inverse_of: :runner_namespaces
belongs_to :namespace, inverse_of: :runner_namespaces, class_name: '::Namespace'
diff --git a/app/models/ci/runner_project.rb b/app/models/ci/runner_project.rb
index af2595ce4af..e1c435e9b1f 100644
--- a/app/models/ci/runner_project.rb
+++ b/app/models/ci/runner_project.rb
@@ -1,14 +1,14 @@
# frozen_string_literal: true
module Ci
- class RunnerProject < ApplicationRecord
- extend Gitlab::Ci::Model
+ class RunnerProject < Ci::ApplicationRecord
include Limitable
self.limit_name = 'ci_registered_project_runners'
self.limit_scope = :project
self.limit_relation = :recent_runners
self.limit_feature_flag = :ci_runner_limits
+ self.limit_feature_flag_for_override = :ci_runner_limits_override
belongs_to :runner, inverse_of: :runner_projects
belongs_to :project, inverse_of: :runner_projects
diff --git a/app/models/ci/running_build.rb b/app/models/ci/running_build.rb
index 9446cfa05da..ae38d54862d 100644
--- a/app/models/ci/running_build.rb
+++ b/app/models/ci/running_build.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
module Ci
- class RunningBuild < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class RunningBuild < Ci::ApplicationRecord
belongs_to :project
belongs_to :build, class_name: 'Ci::Build'
belongs_to :runner, class_name: 'Ci::Runner'
diff --git a/app/models/ci/sources/pipeline.rb b/app/models/ci/sources/pipeline.rb
index f19aac213be..f78caf710a6 100644
--- a/app/models/ci/sources/pipeline.rb
+++ b/app/models/ci/sources/pipeline.rb
@@ -2,7 +2,9 @@
module Ci
module Sources
- class Pipeline < ApplicationRecord
+ class Pipeline < Ci::ApplicationRecord
+ include Ci::NamespacedModelName
+
self.table_name = "ci_sources_pipelines"
belongs_to :project, class_name: "Project"
diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb
index d00066b778d..39e26bf2785 100644
--- a/app/models/ci/stage.rb
+++ b/app/models/ci/stage.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class Stage < ApplicationRecord
- extend Gitlab::Ci::Model
+ class Stage < Ci::ApplicationRecord
include Importable
include Ci::HasStatus
include Gitlab::OptimisticLocking
diff --git a/app/models/ci/trigger.rb b/app/models/ci/trigger.rb
index 6e27abb9f5b..595315f14ab 100644
--- a/app/models/ci/trigger.rb
+++ b/app/models/ci/trigger.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class Trigger < ApplicationRecord
- extend Gitlab::Ci::Model
+ class Trigger < Ci::ApplicationRecord
include Presentable
belongs_to :project
diff --git a/app/models/ci/trigger_request.rb b/app/models/ci/trigger_request.rb
index 5daf3dd192d..b645f7ee2bb 100644
--- a/app/models/ci/trigger_request.rb
+++ b/app/models/ci/trigger_request.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
module Ci
- class TriggerRequest < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class TriggerRequest < Ci::ApplicationRecord
belongs_to :trigger
belongs_to :pipeline, foreign_key: :commit_id
has_many :builds
diff --git a/app/models/ci/unit_test.rb b/app/models/ci/unit_test.rb
index 9fddd9c6002..96b701840ea 100644
--- a/app/models/ci/unit_test.rb
+++ b/app/models/ci/unit_test.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
module Ci
- class UnitTest < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class UnitTest < Ci::ApplicationRecord
MAX_NAME_SIZE = 255
MAX_SUITE_NAME_SIZE = 255
diff --git a/app/models/ci/unit_test_failure.rb b/app/models/ci/unit_test_failure.rb
index 480f9cefb8e..a5aa3b70e37 100644
--- a/app/models/ci/unit_test_failure.rb
+++ b/app/models/ci/unit_test_failure.rb
@@ -1,9 +1,7 @@
# frozen_string_literal: true
module Ci
- class UnitTestFailure < ApplicationRecord
- extend Gitlab::Ci::Model
-
+ class UnitTestFailure < Ci::ApplicationRecord
REPORT_WINDOW = 14.days
validates :unit_test, :build, :failed_at, presence: true
diff --git a/app/models/ci/variable.rb b/app/models/ci/variable.rb
index 84505befc5c..1e91f248fc4 100644
--- a/app/models/ci/variable.rb
+++ b/app/models/ci/variable.rb
@@ -1,8 +1,7 @@
# frozen_string_literal: true
module Ci
- class Variable < ApplicationRecord
- extend Gitlab::Ci::Model
+ class Variable < Ci::ApplicationRecord
include Ci::HasVariable
include Presentable
include Ci::Maskable