提交 70d015d1 编写于 作者: S Shinya Maeda 提交者: Alessio Caiazza

Cleanup drop_stale_scheduled_builds code

上级 a220e72c
......@@ -10,6 +10,7 @@ class StuckCiJobsWorker
BUILD_PENDING_OUTDATED_TIMEOUT = 1.day
BUILD_SCHEDULED_OUTDATED_TIMEOUT = 1.hour
BUILD_PENDING_STUCK_TIMEOUT = 1.hour
BUILD_SCHEDULED_OUTDATED_BATCH_SIZE = 100
def perform
return unless try_obtain_lease
......@@ -68,8 +69,12 @@ class StuckCiJobsWorker
# `ci_builds` table has a partial index on `id` with `scheduled_at <> NULL` condition.
# Therefore this query's first step uses Index Search, and the following expensive
# filter `scheduled_at < ?` will only perform on a small subset (max: 100 rows)
Ci::Build.include(EachBatch).where('scheduled_at IS NOT NULL').each_batch(of: 100) do |relation|
relation.where('scheduled_at < ?', BUILD_SCHEDULED_OUTDATED_TIMEOUT.ago).find_each do |build|
Ci::Build.include(EachBatch)
.where('scheduled_at IS NOT NULL')
.each_batch(of: BUILD_SCHEDULED_OUTDATED_BATCH_SIZE) do |relation|
relation
.where('scheduled_at < ?', BUILD_SCHEDULED_OUTDATED_TIMEOUT.ago)
.find_each(batch_size: BUILD_SCHEDULED_OUTDATED_BATCH_SIZE) do |build|
drop_build(:outdated, build, :scheduled, BUILD_SCHEDULED_OUTDATED_TIMEOUT, :schedule_expired)
end
end
......
......@@ -189,4 +189,26 @@ class ScheduledJobFixture
def cancel_pipeline
Ci::Pipeline.last.cancel_running
end
def create_stale_scheduled_builds
count = 100
rows = []
last_pipeline = Ci::Pipeline.last
last_stage = last_pipeline.stages.last
count.times do |i|
rows << {
name: "delayed-job-bulk-#{i}",
project_id: project.id,
commit_id: last_pipeline.id,
status: 'scheduled',
scheduled_at: 1.day.ago,
user_id: user.id,
stage_id: last_stage.id,
type: 'Ci::Build'
}
end
Gitlab::Database.bulk_insert('ci_builds', rows)
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册