Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/workers/pipeline_schedule_worker.rb')
-rw-r--r--app/workers/pipeline_schedule_worker.rb27
1 files changed, 21 insertions, 6 deletions
diff --git a/app/workers/pipeline_schedule_worker.rb b/app/workers/pipeline_schedule_worker.rb
index ca589acf26c..6237f64fa86 100644
--- a/app/workers/pipeline_schedule_worker.rb
+++ b/app/workers/pipeline_schedule_worker.rb
@@ -10,6 +10,8 @@ class PipelineScheduleWorker # rubocop:disable Scalability/IdempotentWorker
LOCK_RETRY = 3
LOCK_TTL = 5.minutes
+ DELAY = 7.seconds
+ BATCH_SIZE = 500
feature_category :continuous_integration
worker_resource_boundary :cpu
@@ -20,12 +22,8 @@ class PipelineScheduleWorker # rubocop:disable Scalability/IdempotentWorker
.select(:id, :owner_id, :project_id) # Minimize the selected columns
.runnable_schedules
.preloaded
- .find_in_batches do |schedules|
- RunPipelineScheduleWorker.bulk_perform_async_with_contexts(
- schedules,
- arguments_proc: ->(schedule) { [schedule.id, schedule.owner_id, { scheduling: true }] },
- context_proc: ->(schedule) { { project: schedule.project, user: schedule.owner } }
- )
+ .find_in_batches(batch_size: BATCH_SIZE).with_index do |schedules, index| # rubocop: disable CodeReuse/ActiveRecord -- activates because of batch_size
+ enqueue_run_pipeline_schedule_worker(schedules, index)
end
end
end
@@ -42,4 +40,21 @@ class PipelineScheduleWorker # rubocop:disable Scalability/IdempotentWorker
retries: LOCK_RETRY
}
end
+
+ def enqueue_run_pipeline_schedule_worker(schedules, index)
+ if ::Feature.enabled?(:run_pipeline_schedule_worker_with_delay)
+ RunPipelineScheduleWorker.bulk_perform_in_with_contexts(
+ [1, index * DELAY].max,
+ schedules,
+ arguments_proc: ->(schedule) { [schedule.id, schedule.owner_id, { scheduling: true }] },
+ context_proc: ->(schedule) { { project: schedule.project, user: schedule.owner } }
+ )
+ else
+ RunPipelineScheduleWorker.bulk_perform_async_with_contexts(
+ schedules,
+ arguments_proc: ->(schedule) { [schedule.id, schedule.owner_id, { scheduling: true }] },
+ context_proc: ->(schedule) { { project: schedule.project, user: schedule.owner } }
+ )
+ end
+ end
end