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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
b4d7ee7b
Commit
b4d7ee7b
authored
Sep 30, 2021
by
Allison Browne
Committed by
Fabio Pitino
Sep 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize StuckCiJobsWorker running builds query
parent
72148118
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
20 deletions
+49
-20
app/services/ci/stuck_builds/drop_running_service.rb
app/services/ci/stuck_builds/drop_running_service.rb
+6
-1
config/feature_flags/development/ci_new_query_for_running_stuck_jobs.yml
...flags/development/ci_new_query_for_running_stuck_jobs.yml
+8
-0
spec/services/ci/stuck_builds/drop_running_service_spec.rb
spec/services/ci/stuck_builds/drop_running_service_spec.rb
+35
-19
No files found.
app/services/ci/stuck_builds/drop_running_service.rb
View file @
b4d7ee7b
...
...
@@ -16,7 +16,12 @@ module Ci
private
def
running_timed_out_builds
Ci
::
Build
.
running
.
updated_at_before
(
BUILD_RUNNING_OUTDATED_TIMEOUT
.
ago
)
if
Feature
.
enabled?
(
:ci_new_query_for_running_stuck_jobs
,
default_enabled: :yaml
)
running_builds
=
Ci
::
Build
.
running
.
created_at_before
(
BUILD_RUNNING_OUTDATED_TIMEOUT
.
ago
).
order
(
created_at: :asc
,
project_id: :asc
)
# rubocop: disable CodeReuse/ActiveRecord
Ci
::
Build
.
id_in
(
running_builds
).
updated_at_before
(
BUILD_RUNNING_OUTDATED_TIMEOUT
.
ago
)
else
Ci
::
Build
.
running
.
updated_at_before
(
BUILD_RUNNING_OUTDATED_TIMEOUT
.
ago
)
end
end
end
end
...
...
config/feature_flags/development/ci_new_query_for_running_stuck_jobs.yml
0 → 100644
View file @
b4d7ee7b
---
name
:
ci_new_query_for_running_stuck_jobs
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/71013
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/339264
milestone
:
'
14.4'
type
:
development
group
:
group::pipeline execution
default_enabled
:
false
spec/services/ci/stuck_builds/drop_running_service_spec.rb
View file @
b4d7ee7b
...
...
@@ -17,20 +17,47 @@ RSpec.describe Ci::StuckBuilds::DropRunningService do
job
.
update!
(
job_attributes
)
end
context
'when job is running'
do
let
(
:status
)
{
'running'
}
around
do
|
example
|
freeze_time
{
example
.
run
}
end
shared_examples
'running builds'
do
context
'when job is running'
do
let
(
:status
)
{
'running'
}
let
(
:outdated_time
)
{
described_class
::
BUILD_RUNNING_OUTDATED_TIMEOUT
.
ago
-
30
.
minutes
}
let
(
:fresh_time
)
{
described_class
::
BUILD_RUNNING_OUTDATED_TIMEOUT
.
ago
+
30
.
minutes
}
context
'when job is outdated'
do
let
(
:created_at
)
{
outdated_time
}
let
(
:updated_at
)
{
outdated_time
}
it_behaves_like
'job is dropped'
end
context
'when job was updated_at more than an hour ago'
do
let
(
:updated_at
)
{
2
.
hours
.
ago
}
context
'when job is fresh'
do
let
(
:created_at
)
{
fresh_time
}
let
(
:updated_at
)
{
fresh_time
}
it_behaves_like
'job is dropped'
it_behaves_like
'job is unchanged'
end
context
'when job freshly updated'
do
let
(
:created_at
)
{
outdated_time
}
let
(
:updated_at
)
{
fresh_time
}
it_behaves_like
'job is unchanged'
end
end
end
context
'when job was updated in less than 1 hour ago'
do
let
(
:updated_at
)
{
30
.
minutes
.
ago
}
include_examples
'running builds'
it_behaves_like
'job is unchanged'
context
'when ci_new_query_for_running_stuck_jobs flag is disabled'
do
before
do
stub_feature_flags
(
ci_new_query_for_running_stuck_jobs:
false
)
end
include_examples
'running builds'
end
%w(success skipped failed canceled scheduled pending)
.
each
do
|
status
|
...
...
@@ -51,15 +78,4 @@ RSpec.describe Ci::StuckBuilds::DropRunningService do
end
end
end
context
'for deleted project'
do
let
(
:status
)
{
'running'
}
let
(
:updated_at
)
{
2
.
days
.
ago
}
before
do
job
.
project
.
update!
(
pending_delete:
true
)
end
it_behaves_like
'job is dropped'
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