Commit 554e3e67 authored by Matthias Käppler's avatar Matthias Käppler

Merge branch '356433-fix-re-enqueue-in-enqueuer' into 'master'

Enqueuer job: fix the re enqueue

See merge request gitlab-org/gitlab!83527
parents 0e060c73 c9f7d761
...@@ -6,17 +6,24 @@ module ContainerRegistry ...@@ -6,17 +6,24 @@ module ContainerRegistry
include ApplicationWorker include ApplicationWorker
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
include ExclusiveLeaseGuard
DEFAULT_LEASE_TIMEOUT = 1.hour.to_i.freeze
data_consistency :always data_consistency :always
feature_category :container_registry feature_category :container_registry
urgency :low urgency :low
deduplicate :until_executed, including_scheduled: true deduplicate :until_executing, including_scheduled: true
idempotent! idempotent!
def perform def perform
return unless runnable? re_enqueue = false
try_obtain_lease do
break unless runnable?
re_enqueue_if_capacity if handle_aborted_migration || handle_next_migration re_enqueue = handle_aborted_migration || handle_next_migration
end
re_enqueue_if_capacity if re_enqueue
end end
private private
...@@ -143,6 +150,16 @@ module ContainerRegistry ...@@ -143,6 +150,16 @@ module ContainerRegistry
log_extra_metadata_on_done(:container_repository_id, repository&.id) log_extra_metadata_on_done(:container_repository_id, repository&.id)
log_extra_metadata_on_done(:container_repository_path, repository&.path) log_extra_metadata_on_done(:container_repository_path, repository&.path)
end end
# used by ExclusiveLeaseGuard
def lease_key
'container_registry:migration:enqueuer_worker'
end
# used by ExclusiveLeaseGuard
def lease_timeout
DEFAULT_LEASE_TIMEOUT
end
end end
end end
end end
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe ContainerRegistry::Migration::EnqueuerWorker, :aggregate_failures do RSpec.describe ContainerRegistry::Migration::EnqueuerWorker, :aggregate_failures, :clean_gitlab_redis_shared_state do
include ExclusiveLeaseHelpers
let_it_be_with_reload(:container_repository) { create(:container_repository, created_at: 2.days.ago) } let_it_be_with_reload(:container_repository) { create(:container_repository, created_at: 2.days.ago) }
let(:worker) { described_class.new } let(:worker) { described_class.new }
...@@ -224,6 +226,21 @@ RSpec.describe ContainerRegistry::Migration::EnqueuerWorker, :aggregate_failures ...@@ -224,6 +226,21 @@ RSpec.describe ContainerRegistry::Migration::EnqueuerWorker, :aggregate_failures
end end
end end
context 'with the exclusive lease taken' do
let(:lease_key) { worker.send(:lease_key) }
before do
stub_exclusive_lease_taken(lease_key, timeout: 1.hour)
end
it 'does not perform' do
expect(worker).not_to receive(:runnable?)
expect(worker).not_to receive(:re_enqueue_if_capacity)
subject
end
end
def expect_log_extra_metadata(metadata) def expect_log_extra_metadata(metadata)
metadata.each do |key, value| metadata.each do |key, value|
expect(worker).to receive(:log_extra_metadata_on_done).with(key, value) expect(worker).to receive(:log_extra_metadata_on_done).with(key, value)
......
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