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
def perform_throttled
try_obtain_lease do
with_runnable_policy do |policy|
policy.schedule_next_run!
ContainerRepository.for_project_id(policy.id)
.each_batch do |relation|
relation.update_all(expiration_policy_cleanup_status: :cleanup_scheduled)
end
ContainerExpirationPolicy.transaction do
policy.schedule_next_run!
ContainerRepository.for_project_id(policy.id)
.each_batch do |relation|
relation.update_all(expiration_policy_cleanup_status: :cleanup_scheduled)
end
end
end
ContainerExpirationPolicies::CleanupContainerRepositoryWorker.perform_with_capacity
......@@ -53,9 +55,7 @@ class ContainerExpirationPolicyWorker # rubocop:disable Scalability/IdempotentWo
scope.each do |policy|
if policy.valid?
ContainerExpirationPolicy.transaction do
yield policy
end
yield policy
else
disable_invalid_policy!(policy)
end
......
---
title: Fix transaction usage in ContainerExpirationPolicyWorker
merge_request: 46217
author:
type: fixed
......@@ -106,12 +106,11 @@ RSpec.describe ContainerExpirationPolicyWorker do
context 'a valid policy' do
it 'runs the policy' do
service = instance_double(ContainerExpirationPolicyService, execute: true)
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
......
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