Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
c514636a
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c514636a
编写于
9月 26, 2018
作者:
S
Shinya Maeda
提交者:
Alessio Caiazza
10月 02, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify StuckCiJobsWorker
上级
b1d24c0d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
31 deletion
+26
-31
app/services/ci/process_pipeline_service.rb
app/services/ci/process_pipeline_service.rb
+1
-1
app/workers/stuck_ci_jobs_worker.rb
app/workers/stuck_ci_jobs_worker.rb
+25
-30
未找到文件。
app/services/ci/process_pipeline_service.rb
浏览文件 @
c514636a
...
...
@@ -56,7 +56,7 @@ module Ci
when
'manual'
%w[success skipped]
when
'delayed'
%w[success skipped]
# This might be `success` only
%w[success skipped]
else
[]
end
...
...
app/workers/stuck_ci_jobs_worker.rb
浏览文件 @
c514636a
...
...
@@ -16,10 +16,10 @@ class StuckCiJobsWorker
Rails
.
logger
.
info
"
#{
self
.
class
}
: Cleaning stuck builds"
drop
:running
,
condition_for_outdated_running
,
:stuck_or_timeout_failure
drop
:pending
,
condition_for_outdated_pending
,
:stuck_or_timeout_failure
drop
:scheduled
,
condition_for_outdated_scheduled
,
:schedule_expired
drop_st
uck
:pending
,
condition_for_outdated_pending_stuck
,
:stuck_or_timeout_failure
drop
:running
,
BUILD_RUNNING_OUTDATED_TIMEOUT
drop
:pending
,
BUILD_PENDING_OUTDATED_TIMEOUT
drop
_stuck
:pending
,
BUILD_PENDING_STUCK_TIMEOUT
drop_st
ale_scheduled_builds
remove_lease
end
...
...
@@ -34,41 +34,25 @@ class StuckCiJobsWorker
Gitlab
::
ExclusiveLease
.
cancel
(
EXCLUSIVE_LEASE_KEY
,
@uuid
)
end
def
drop
(
status
,
condition
,
reason
)
search
(
status
,
condition
)
do
|
build
|
drop_build
:outdated
,
build
,
status
,
reason
def
drop
(
status
,
timeout
)
search
(
status
,
timeout
)
do
|
build
|
drop_build
:outdated
,
build
,
status
,
timeout
,
:stuck_or_timeout_failure
end
end
def
drop_stuck
(
status
,
condition
,
reason
)
search
(
status
,
condition
)
do
|
build
|
def
drop_stuck
(
status
,
timeout
)
search
(
status
,
timeout
)
do
|
build
|
break
unless
build
.
stuck?
drop_build
:stuck
,
build
,
status
,
reason
drop_build
:stuck
,
build
,
status
,
timeout
,
:stuck_or_timeout_failure
end
end
def
condition_for_outdated_running
[
"updated_at < ?"
,
BUILD_RUNNING_OUTDATED_TIMEOUT
.
ago
]
end
def
condition_for_outdated_pending
[
"updated_at < ?"
,
BUILD_PENDING_OUTDATED_TIMEOUT
.
ago
]
end
def
condition_for_outdated_scheduled
[
"scheduled_at <> '' && scheduled_at < ?"
,
BUILD_SCHEDULED_OUTDATED_TIMEOUT
.
ago
]
end
def
condition_for_outdated_pending_stuck
[
"updated_at < ?"
,
BUILD_PENDING_STUCK_TIMEOUT
.
ago
]
end
# rubocop: disable CodeReuse/ActiveRecord
def
search
(
status
,
condition
)
def
search
(
status
,
timeout
)
loop
do
jobs
=
Ci
::
Build
.
where
(
status:
status
)
.
where
(
*
condition
)
.
where
(
'ci_builds.updated_at < ?'
,
timeout
.
ago
)
.
includes
(
:tags
,
:runner
,
project: :namespace
)
.
limit
(
100
)
.
to_a
...
...
@@ -81,10 +65,21 @@ class StuckCiJobsWorker
end
# rubocop: enable CodeReuse/ActiveRecord
def
drop_build
(
type
,
build
,
status
,
reason
)
Rails
.
logger
.
info
"
#{
self
.
class
}
: Dropping
#{
type
}
build
#{
build
.
id
}
for runner
#{
build
.
runner_id
}
(status:
#{
status
}
)"
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
}
, reason:
#{
reason
}
)"
Gitlab
::
OptimisticLocking
.
retry_lock
(
build
,
3
)
do
|
b
|
b
.
drop
(
reason
)
end
end
def
drop_stale_scheduled_builds
# `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
(
EachBach
).
where
(
'scheduled_at <> NULL'
).
each_batch
(
of:
100
)
do
|
relation
|
relation
.
where
(
'scheduled_at < ?'
,
BUILD_SCHEDULED_OUTDATED_TIMEOUT
.
ago
).
find_each
do
|
build
|
drop_build
(
:outdated
,
build
,
:scheduled
,
BUILD_SCHEDULED_OUTDATED_TIMEOUT
,
:schedule_expired
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录