Commit bd9f7eef authored by Sean McGivern's avatar Sean McGivern

Merge branch 'bvl-clear-context-metadata-when-scheduling-mirrors' into 'master'

Clear context when scheduling mirroring jobs

See merge request gitlab-org/gitlab!22469
parents 88f45b39 bb4e47a8
......@@ -14,22 +14,24 @@ class UpdateAllMirrorsWorker
def perform
return if Gitlab::Database.read_only?
scheduled = 0
with_lease do
scheduled = schedule_mirrors!
Gitlab::ApplicationContext.with_context({ user: nil, project: nil, namespace: nil }) do
scheduled = 0
with_lease do
scheduled = schedule_mirrors!
end
# If we didn't get the lease, or no updates were scheduled, exit early
break unless scheduled > 0
# Wait to give some jobs a chance to complete
Kernel.sleep(RESCHEDULE_WAIT)
# If there's capacity left now (some jobs completed),
# reschedule this job to enqueue more work.
#
# This is in addition to the regular (cron-like) scheduling of this job.
UpdateAllMirrorsWorker.perform_async if Gitlab::Mirror.reschedule_immediately?
end
# If we didn't get the lease, or no updates were scheduled, exit early
return unless scheduled > 0
# Wait to give some jobs a chance to complete
Kernel.sleep(RESCHEDULE_WAIT)
# If there's capacity left now (some jobs completed),
# reschedule this job to enqueue more work.
#
# This is in addition to the regular (cron-like) scheduling of this job.
UpdateAllMirrorsWorker.perform_async if Gitlab::Mirror.reschedule_immediately?
end
# rubocop: disable CodeReuse/ActiveRecord
......
......@@ -27,6 +27,26 @@ describe UpdateAllMirrorsWorker do
worker.perform
end
it 'removes metadata except correlation_id from the application context before scheduling mirrors' do
inner_context = nil
outer_context = nil
Gitlab::ApplicationContext.with_context(project: build_stubbed(:project)) do
outer_context = Labkit::Context.current.to_h
expect(worker).to receive(:schedule_mirrors!) do
inner_context = Labkit::Context.current.to_h
# `schedule_mirrors!` needs to return an integer.
0
end
end
worker.perform
expect(inner_context).to eq(outer_context.slice('correlation_id'))
end
it 'schedules mirrors' do
expect(worker).to receive(:schedule_mirrors!).and_call_original
......
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