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
58756075
Commit
58756075
authored
Sep 27, 2018
by
Shinya Maeda
Committed by
Alessio Caiazza
Oct 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix StuckCiJobsWorker and added tests
parent
71fc37c9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
2 deletions
+43
-2
app/models/commit_status.rb
app/models/commit_status.rb
+1
-1
app/workers/stuck_ci_jobs_worker.rb
app/workers/stuck_ci_jobs_worker.rb
+1
-1
spec/workers/stuck_ci_jobs_worker_spec.rb
spec/workers/stuck_ci_jobs_worker_spec.rb
+41
-0
No files found.
app/models/commit_status.rb
View file @
58756075
...
@@ -84,7 +84,7 @@ class CommitStatus < ActiveRecord::Base
...
@@ -84,7 +84,7 @@ class CommitStatus < ActiveRecord::Base
end
end
event
:drop
do
event
:drop
do
transition
[
:created
,
:pending
,
:running
]
=>
:failed
transition
[
:created
,
:pending
,
:running
,
:scheduled
]
=>
:failed
end
end
event
:success
do
event
:success
do
...
...
app/workers/stuck_ci_jobs_worker.rb
View file @
58756075
...
@@ -68,7 +68,7 @@ class StuckCiJobsWorker
...
@@ -68,7 +68,7 @@ class StuckCiJobsWorker
# `ci_builds` table has a partial index on `id` with `scheduled_at <> NULL` condition.
# `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
# 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)
# filter `scheduled_at < ?` will only perform on a small subset (max: 100 rows)
Ci
::
Build
.
include
(
EachBatch
).
where
(
'scheduled_at
<>
NULL'
).
each_batch
(
of:
100
)
do
|
relation
|
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
|
relation
.
where
(
'scheduled_at < ?'
,
BUILD_SCHEDULED_OUTDATED_TIMEOUT
.
ago
).
find_each
do
|
build
|
drop_build
(
:outdated
,
build
,
:scheduled
,
BUILD_SCHEDULED_OUTDATED_TIMEOUT
,
:schedule_expired
)
drop_build
(
:outdated
,
build
,
:scheduled
,
BUILD_SCHEDULED_OUTDATED_TIMEOUT
,
:schedule_expired
)
end
end
...
...
spec/workers/stuck_ci_jobs_worker_spec.rb
View file @
58756075
...
@@ -127,6 +127,47 @@ describe StuckCiJobsWorker do
...
@@ -127,6 +127,47 @@ describe StuckCiJobsWorker do
end
end
end
end
describe
'drop_stale_scheduled_builds'
do
let
(
:status
)
{
'scheduled'
}
let
(
:updated_at
)
{
}
context
'when scheduled at 2 hours ago but it is not executed yet'
do
let!
(
:job
)
{
create
(
:ci_build
,
:scheduled
,
scheduled_at:
2
.
hours
.
ago
)
}
it
'drops the stale scheduled build'
do
expect
(
Ci
::
Build
.
scheduled
.
count
).
to
eq
(
1
)
expect
(
job
).
to
be_scheduled
worker
.
perform
job
.
reload
expect
(
Ci
::
Build
.
scheduled
.
count
).
to
eq
(
0
)
expect
(
job
).
to
be_failed
expect
(
job
).
to
be_schedule_expired
end
end
context
'when scheduled at 30 minutes ago but it is not executed yet'
do
let!
(
:job
)
{
create
(
:ci_build
,
:scheduled
,
scheduled_at:
30
.
minutes
.
ago
)
}
it
'does not drop the stale scheduled build yet'
do
expect
(
Ci
::
Build
.
scheduled
.
count
).
to
eq
(
1
)
expect
(
job
).
to
be_scheduled
worker
.
perform
expect
(
Ci
::
Build
.
scheduled
.
count
).
to
eq
(
1
)
expect
(
job
).
to
be_scheduled
end
end
context
'when there are no stale scheduled builds'
do
it
'does not drop the stale scheduled build yet'
do
expect
{
worker
.
perform
}.
not_to
raise_error
end
end
end
describe
'exclusive lease'
do
describe
'exclusive lease'
do
let
(
:status
)
{
'running'
}
let
(
:status
)
{
'running'
}
let
(
:updated_at
)
{
2
.
days
.
ago
}
let
(
:updated_at
)
{
2
.
days
.
ago
}
...
...
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