Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
0ba385b3
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,发现更多精彩内容 >>
未验证
提交
0ba385b3
编写于
2月 07, 2017
作者:
T
Tomasz Maczukin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add exclusive lease for stuck_ci_builds_worker
上级
a4e996d7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
3 deletion
+27
-3
app/workers/stuck_ci_builds_worker.rb
app/workers/stuck_ci_builds_worker.rb
+11
-2
spec/workers/stuck_ci_builds_worker_spec.rb
spec/workers/stuck_ci_builds_worker_spec.rb
+16
-1
未找到文件。
app/workers/stuck_ci_builds_worker.rb
浏览文件 @
0ba385b3
...
@@ -7,7 +7,9 @@ class StuckCiBuildsWorker
...
@@ -7,7 +7,9 @@ class StuckCiBuildsWorker
BUILD_PENDING_STUCK_TIMEOUT
=
1
.
hour
BUILD_PENDING_STUCK_TIMEOUT
=
1
.
hour
def
perform
def
perform
Rails
.
logger
.
info
'Cleaning stuck builds'
return
unless
try_obtain_lease
Rails
.
logger
.
info
"
#{
self
.
class
}
: Cleaning stuck builds"
drop
:running
,
BUILD_RUNNING_OUTDATED_TIMEOUT
drop
:running
,
BUILD_RUNNING_OUTDATED_TIMEOUT
drop
:pending
,
BUILD_PENDING_OUTDATED_TIMEOUT
drop
:pending
,
BUILD_PENDING_OUTDATED_TIMEOUT
...
@@ -16,6 +18,13 @@ class StuckCiBuildsWorker
...
@@ -16,6 +18,13 @@ class StuckCiBuildsWorker
private
private
def
try_obtain_lease
Gitlab
::
ExclusiveLease
.
new
(
'stuck_ci_builds_worker_lease'
,
timeout:
30
.
minutes
).
try_obtain
end
def
drop
(
status
,
timeout
)
def
drop
(
status
,
timeout
)
search
(
status
,
timeout
)
do
|
build
|
search
(
status
,
timeout
)
do
|
build
|
drop_build
:outdated
,
build
,
status
,
timeout
drop_build
:outdated
,
build
,
status
,
timeout
...
@@ -37,7 +46,7 @@ class StuckCiBuildsWorker
...
@@ -37,7 +46,7 @@ class StuckCiBuildsWorker
end
end
def
drop_build
(
type
,
build
,
status
,
timeout
)
def
drop_build
(
type
,
build
,
status
,
timeout
)
Rails
.
logger
.
info
"
#{
self
.
class
}
: Dropping
#{
type
.
to_s
}
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
}
)"
build
.
drop
build
.
drop
end
end
end
end
spec/workers/stuck_ci_builds_worker_spec.rb
浏览文件 @
0ba385b3
...
@@ -10,7 +10,10 @@ describe StuckCiBuildsWorker do
...
@@ -10,7 +10,10 @@ describe StuckCiBuildsWorker do
build
.
status
build
.
status
end
end
before
{
build
.
update!
(
status:
status
,
updated_at:
updated_at
)
}
before
do
build
.
update!
(
status:
status
,
updated_at:
updated_at
)
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
true
)
end
shared_examples
'build is dropped'
do
shared_examples
'build is dropped'
do
it
'changes status'
do
it
'changes status'
do
...
@@ -96,4 +99,16 @@ describe StuckCiBuildsWorker do
...
@@ -96,4 +99,16 @@ describe StuckCiBuildsWorker do
worker
.
perform
worker
.
perform
end
end
end
end
describe
'exclusive lease'
do
let
(
:status
)
{
'running'
}
let
(
:updated_at
)
{
2
.
days
.
ago
}
it
'is guard by exclusive lease'
do
worker
.
perform
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
false
)
expect
(
worker
).
not_to
receive
(
:drop
)
worker
.
perform
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录