Commit 1219ece0 authored by Stan Hu's avatar Stan Hu

Merge branch '273140-fix-transaction-issue-in-container-expiration-policy-worker' into 'master'

Fix transaction usage in ContainerExpirationPolicyWorker

See merge request gitlab-org/gitlab!46217
parents 1e64a81f f4877ee1
...@@ -30,11 +30,13 @@ class ContainerExpirationPolicyWorker # rubocop:disable Scalability/IdempotentWo ...@@ -30,11 +30,13 @@ class ContainerExpirationPolicyWorker # rubocop:disable Scalability/IdempotentWo
def perform_throttled def perform_throttled
try_obtain_lease do try_obtain_lease do
with_runnable_policy do |policy| with_runnable_policy do |policy|
policy.schedule_next_run! ContainerExpirationPolicy.transaction do
ContainerRepository.for_project_id(policy.id) policy.schedule_next_run!
.each_batch do |relation| ContainerRepository.for_project_id(policy.id)
relation.update_all(expiration_policy_cleanup_status: :cleanup_scheduled) .each_batch do |relation|
end relation.update_all(expiration_policy_cleanup_status: :cleanup_scheduled)
end
end
end end
ContainerExpirationPolicies::CleanupContainerRepositoryWorker.perform_with_capacity ContainerExpirationPolicies::CleanupContainerRepositoryWorker.perform_with_capacity
...@@ -53,9 +55,7 @@ class ContainerExpirationPolicyWorker # rubocop:disable Scalability/IdempotentWo ...@@ -53,9 +55,7 @@ class ContainerExpirationPolicyWorker # rubocop:disable Scalability/IdempotentWo
scope.each do |policy| scope.each do |policy|
if policy.valid? if policy.valid?
ContainerExpirationPolicy.transaction do yield policy
yield policy
end
else else
disable_invalid_policy!(policy) disable_invalid_policy!(policy)
end end
......
---
title: Fix transaction usage in ContainerExpirationPolicyWorker
merge_request: 46217
author:
type: fixed
...@@ -106,12 +106,11 @@ RSpec.describe ContainerExpirationPolicyWorker do ...@@ -106,12 +106,11 @@ RSpec.describe ContainerExpirationPolicyWorker do
context 'a valid policy' do context 'a valid policy' do
it 'runs the policy' do it 'runs the policy' do
service = instance_double(ContainerExpirationPolicyService, execute: true)
expect(ContainerExpirationPolicyService) expect(ContainerExpirationPolicyService)
.to receive(:new).with(container_expiration_policy.project, user).and_return(service) .to receive(:new).with(container_expiration_policy.project, user).and_call_original
expect(CleanupContainerRepositoryWorker).to receive(:perform_async).once.and_call_original
subject expect { subject }.not_to raise_error
end end
end end
......
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