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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /app/models/container_repository.rb
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'app/models/container_repository.rb')
-rw-r--r--app/models/container_repository.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb
index e2bdf8ffce2..6e0d0e347c9 100644
--- a/app/models/container_repository.rb
+++ b/app/models/container_repository.rb
@@ -7,6 +7,7 @@ class ContainerRepository < ApplicationRecord
include Sortable
WAITING_CLEANUP_STATUSES = %i[cleanup_scheduled cleanup_unfinished].freeze
+ REQUIRING_CLEANUP_STATUSES = %i[cleanup_unscheduled cleanup_scheduled].freeze
belongs_to :project
@@ -31,6 +32,7 @@ class ContainerRepository < ApplicationRecord
scope :for_project_id, ->(project_id) { where(project_id: project_id) }
scope :search_by_name, ->(query) { fuzzy_search(query, [:name], use_minimum_char_limit: false) }
scope :waiting_for_cleanup, -> { where(expiration_policy_cleanup_status: WAITING_CLEANUP_STATUSES) }
+ scope :expiration_policy_started_at_nil_or_before, ->(timestamp) { where('expiration_policy_started_at < ? OR expiration_policy_started_at IS NULL', timestamp) }
def self.exists_by_path?(path)
where(
@@ -39,6 +41,23 @@ class ContainerRepository < ApplicationRecord
).exists?
end
+ def self.with_enabled_policy
+ joins("INNER JOIN container_expiration_policies ON container_repositories.project_id = container_expiration_policies.project_id")
+ .where(container_expiration_policies: { enabled: true })
+ end
+
+ def self.requiring_cleanup
+ where(
+ container_repositories: { expiration_policy_cleanup_status: REQUIRING_CLEANUP_STATUSES },
+ project_id: ::ContainerExpirationPolicy.runnable_schedules
+ .select(:project_id)
+ )
+ end
+
+ def self.with_unfinished_cleanup
+ with_enabled_policy.cleanup_unfinished
+ end
+
# rubocop: disable CodeReuse/ServiceClass
def registry
@registry ||= begin
@@ -140,4 +159,4 @@ class ContainerRepository < ApplicationRecord
end
end
-ContainerRepository.prepend_if_ee('EE::ContainerRepository')
+ContainerRepository.prepend_mod_with('ContainerRepository')