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
Boxiang Sun
gitlab-ce
Commits
c9077a0e
Commit
c9077a0e
authored
Sep 25, 2018
by
Shinya Maeda
Committed by
Alessio Caiazza
Oct 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cleanup mechanizm for stale scheduled jobs
parent
f76f6df1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
14 deletions
+19
-14
app/models/commit_status.rb
app/models/commit_status.rb
+2
-1
app/workers/stuck_ci_jobs_worker.rb
app/workers/stuck_ci_jobs_worker.rb
+17
-13
No files found.
app/models/commit_status.rb
View file @
c9077a0e
...
@@ -49,7 +49,8 @@ class CommitStatus < ActiveRecord::Base
...
@@ -49,7 +49,8 @@ class CommitStatus < ActiveRecord::Base
stuck_or_timeout_failure:
3
,
stuck_or_timeout_failure:
3
,
runner_system_failure:
4
,
runner_system_failure:
4
,
missing_dependency_failure:
5
,
missing_dependency_failure:
5
,
runner_unsupported:
6
runner_unsupported:
6
,
schedule_expired:
7
}
}
##
##
...
...
app/workers/stuck_ci_jobs_worker.rb
View file @
c9077a0e
...
@@ -8,6 +8,7 @@ class StuckCiJobsWorker
...
@@ -8,6 +8,7 @@ class StuckCiJobsWorker
BUILD_RUNNING_OUTDATED_TIMEOUT
=
1
.
hour
BUILD_RUNNING_OUTDATED_TIMEOUT
=
1
.
hour
BUILD_PENDING_OUTDATED_TIMEOUT
=
1
.
day
BUILD_PENDING_OUTDATED_TIMEOUT
=
1
.
day
BUILD_SCHEDULED_OUTDATED_TIMEOUT
=
1
.
hour
BUILD_PENDING_STUCK_TIMEOUT
=
1
.
hour
BUILD_PENDING_STUCK_TIMEOUT
=
1
.
hour
def
perform
def
perform
...
@@ -15,9 +16,10 @@ class StuckCiJobsWorker
...
@@ -15,9 +16,10 @@ class StuckCiJobsWorker
Rails
.
logger
.
info
"
#{
self
.
class
}
: Cleaning stuck builds"
Rails
.
logger
.
info
"
#{
self
.
class
}
: Cleaning stuck builds"
drop
:running
,
BUILD_RUNNING_OUTDATED_TIMEOUT
drop
:running
,
:updated_at
,
BUILD_RUNNING_OUTDATED_TIMEOUT
,
:stuck_or_timeout_failure
drop
:pending
,
BUILD_PENDING_OUTDATED_TIMEOUT
drop
:pending
,
:updated_at
,
BUILD_PENDING_OUTDATED_TIMEOUT
,
:stuck_or_timeout_failure
drop_stuck
:pending
,
BUILD_PENDING_STUCK_TIMEOUT
drop
:scheduled
,
:scheduled_at
,
BUILD_SCHEDULED_OUTDATED_TIMEOUT
,
:schedule_expired
drop_stuck
:pending
,
:updated_at
,
BUILD_PENDING_STUCK_TIMEOUT
,
:stuck_or_timeout_failure
remove_lease
remove_lease
end
end
...
@@ -32,25 +34,27 @@ class StuckCiJobsWorker
...
@@ -32,25 +34,27 @@ class StuckCiJobsWorker
Gitlab
::
ExclusiveLease
.
cancel
(
EXCLUSIVE_LEASE_KEY
,
@uuid
)
Gitlab
::
ExclusiveLease
.
cancel
(
EXCLUSIVE_LEASE_KEY
,
@uuid
)
end
end
def
drop
(
status
,
timeout
)
def
drop
(
status
,
column
,
timeout
,
reason
)
search
(
status
,
timeout
)
do
|
build
|
search
(
status
,
column
,
timeout
)
do
|
build
|
drop_build
:outdated
,
build
,
status
,
timeout
drop_build
:outdated
,
build
,
status
,
timeout
,
reason
end
end
end
end
def
drop_stuck
(
status
,
timeout
)
def
drop_stuck
(
status
,
column
,
timeout
,
reason
)
search
(
status
,
timeout
)
do
|
build
|
search
(
status
,
column
,
timeout
)
do
|
build
|
break
unless
build
.
stuck?
break
unless
build
.
stuck?
drop_build
:stuck
,
build
,
status
,
timeout
drop_build
:stuck
,
build
,
status
,
timeout
,
reason
end
end
end
end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
search
(
status
,
timeout
)
def
search
(
status
,
column
,
timeout
)
quoted_column
=
ActiveRecord
::
Base
.
connection
.
quote_column_name
(
column
)
loop
do
loop
do
jobs
=
Ci
::
Build
.
where
(
status:
status
)
jobs
=
Ci
::
Build
.
where
(
status:
status
)
.
where
(
'ci_builds.updated_at < ?'
,
timeout
.
ago
)
.
where
(
"
#{
quoted_column
}
< ?"
,
timeout
.
ago
)
.
includes
(
:tags
,
:runner
,
project: :namespace
)
.
includes
(
:tags
,
:runner
,
project: :namespace
)
.
limit
(
100
)
.
limit
(
100
)
.
to_a
.
to_a
...
@@ -63,10 +67,10 @@ class StuckCiJobsWorker
...
@@ -63,10 +67,10 @@ class StuckCiJobsWorker
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
def
drop_build
(
type
,
build
,
status
,
timeout
)
def
drop_build
(
type
,
build
,
status
,
timeout
,
reason
)
Rails
.
logger
.
info
"
#{
self
.
class
}
: Dropping
#{
type
}
build
#{
build
.
id
}
for runner
#{
build
.
runner_id
}
(status:
#{
status
}
, timeout:
#{
timeout
}
)"
Rails
.
logger
.
info
"
#{
self
.
class
}
: Dropping
#{
type
}
build
#{
build
.
id
}
for runner
#{
build
.
runner_id
}
(status:
#{
status
}
, timeout:
#{
timeout
}
)"
Gitlab
::
OptimisticLocking
.
retry_lock
(
build
,
3
)
do
|
b
|
Gitlab
::
OptimisticLocking
.
retry_lock
(
build
,
3
)
do
|
b
|
b
.
drop
(
:stuck_or_timeout_failure
)
b
.
drop
(
reason
)
end
end
end
end
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