Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
70d015d1
Commit
70d015d1
authored
Oct 01, 2018
by
Shinya Maeda
Committed by
Alessio Caiazza
Oct 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup drop_stale_scheduled_builds code
parent
a220e72c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
app/workers/stuck_ci_jobs_worker.rb
app/workers/stuck_ci_jobs_worker.rb
+7
-2
scheduled_job_fixture.rb
scheduled_job_fixture.rb
+22
-0
No files found.
app/workers/stuck_ci_jobs_worker.rb
View file @
70d015d1
...
...
@@ -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
...
...
scheduled_job_fixture.rb
View file @
70d015d1
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment