Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
6db7c232
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,发现更多精彩内容 >>
未验证
提交
6db7c232
编写于
2月 09, 2017
作者:
T
Tomasz Maczukin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add minor updates
上级
48cb391c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
9 deletion
+32
-9
app/workers/stuck_ci_builds_worker.rb
app/workers/stuck_ci_builds_worker.rb
+13
-5
spec/workers/stuck_ci_builds_worker_spec.rb
spec/workers/stuck_ci_builds_worker_spec.rb
+19
-4
未找到文件。
app/workers/stuck_ci_builds_worker.rb
浏览文件 @
6db7c232
...
...
@@ -2,6 +2,8 @@ class StuckCiBuildsWorker
include
Sidekiq
::
Worker
include
CronjobQueue
EXCLUSIVE_LEASE_KEY
=
'stuck_ci_builds_worker_lease'
BUILD_RUNNING_OUTDATED_TIMEOUT
=
1
.
hour
BUILD_PENDING_OUTDATED_TIMEOUT
=
1
.
day
BUILD_PENDING_STUCK_TIMEOUT
=
1
.
hour
...
...
@@ -11,20 +13,26 @@ class StuckCiBuildsWorker
Rails
.
logger
.
info
"
#{
self
.
class
}
: Cleaning stuck builds"
drop
:running
,
BUILD_RUNNING_OUTDATED_TIMEOUT
drop
:pending
,
BUILD_PENDING_OUTDATED_TIMEOUT
drop
:running
,
BUILD_RUNNING_OUTDATED_TIMEOUT
drop
:pending
,
BUILD_PENDING_OUTDATED_TIMEOUT
drop_stuck
:pending
,
BUILD_PENDING_STUCK_TIMEOUT
remove_lease
end
private
def
try_obtain_lease
Gitlab
::
ExclusiveLease
.
new
(
'stuck_ci_builds_worker_lease'
,
timeout:
30
.
minutes
@uuid
=
Gitlab
::
ExclusiveLease
.
new
(
EXCLUSIVE_LEASE_KEY
,
timeout:
30
.
minutes
).
try_obtain
end
def
remove_lease
Gitlab
::
ExclusiveLease
.
cancel
(
EXCLUSIVE_LEASE_KEY
,
@uuid
)
end
def
drop
(
status
,
timeout
)
search
(
status
,
timeout
)
do
|
build
|
drop_build
:outdated
,
build
,
status
,
timeout
...
...
spec/workers/stuck_ci_builds_worker_spec.rb
浏览文件 @
6db7c232
...
...
@@ -4,6 +4,7 @@ describe StuckCiBuildsWorker do
let!
(
:runner
)
{
create
:ci_runner
}
let!
(
:build
)
{
create
:ci_build
,
runner:
runner
}
let
(
:worker
)
{
described_class
.
new
}
let
(
:exclusive_lease_uuid
)
{
SecureRandom
.
uuid
}
subject
do
build
.
reload
...
...
@@ -12,7 +13,7 @@ describe StuckCiBuildsWorker do
before
do
build
.
update!
(
status:
status
,
updated_at:
updated_at
)
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
true
)
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
exclusive_lease_uuid
)
end
shared_examples
'build is dropped'
do
...
...
@@ -103,12 +104,26 @@ describe StuckCiBuildsWorker do
describe
'exclusive lease'
do
let
(
:status
)
{
'running'
}
let
(
:updated_at
)
{
2
.
days
.
ago
}
let
(
:worker2
)
{
described_class
.
new
}
it
'is guard by exclusive lease'
do
it
'is guard by exclusive lease when executed concurrently'
do
expect
(
worker
).
to
receive
(
:drop
).
at_least
(
:once
)
expect
(
worker2
).
not_to
receive
(
:drop
)
worker
.
perform
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
false
)
expect
(
worker
).
not_to
receive
(
:drop
)
worker2
.
perform
end
it
'can be executed in sequence'
do
expect
(
worker
).
to
receive
(
:drop
).
at_least
(
:once
)
expect
(
worker2
).
to
receive
(
:drop
).
at_least
(
:once
)
worker
.
perform
worker2
.
perform
end
it
'cancels exclusive lease after worker perform'
do
expect
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:cancel
).
with
(
described_class
::
EXCLUSIVE_LEASE_KEY
,
exclusive_lease_uuid
)
worker
.
perform
end
end
end
end
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录