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 ...@@ -14,22 +14,24 @@ class UpdateAllMirrorsWorker
def perform def perform
return if Gitlab::Database.read_only? return if Gitlab::Database.read_only?
scheduled = 0 Gitlab::ApplicationContext.with_context({ user: nil, project: nil, namespace: nil }) do
with_lease do scheduled = 0
scheduled = schedule_mirrors! 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 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 end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
......
...@@ -27,6 +27,26 @@ describe UpdateAllMirrorsWorker do ...@@ -27,6 +27,26 @@ describe UpdateAllMirrorsWorker do
worker.perform worker.perform
end 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 it 'schedules mirrors' do
expect(worker).to receive(:schedule_mirrors!).and_call_original 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