Commit b1bcfe3c authored by Tiger Watson's avatar Tiger Watson

Merge branch '331121-fix-container-repository-requiring-cleanup-scope' into 'master'

Fix the `requiring_cleanup` scope in ContainerRepository model

See merge request gitlab-org/gitlab!62827
parents bf5f38c1 1d40aa40
......@@ -43,16 +43,15 @@ class ContainerRepository < ApplicationRecord
end
def self.with_enabled_policy
joins("INNER JOIN container_expiration_policies ON container_repositories.project_id = container_expiration_policies.project_id")
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)
)
with_enabled_policy
.where(container_repositories: { expiration_policy_cleanup_status: REQUIRING_CLEANUP_STATUSES })
.where('container_repositories.expiration_policy_started_at IS NULL OR container_repositories.expiration_policy_started_at < container_expiration_policies.next_run_at')
.where('container_expiration_policies.next_run_at < ?', Time.zone.now)
end
def self.with_unfinished_cleanup
......
......@@ -434,6 +434,14 @@ RSpec.describe ContainerRepository do
it { is_expected.to eq([repository]) }
end
context 'with repository cleanup started at after policy next run at' do
before do
repository.update!(expiration_policy_started_at: policy.next_run_at + 5.minutes)
end
it { is_expected.to eq([]) }
end
end
describe '.with_unfinished_cleanup' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment