Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ec100a20
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,发现更多精彩内容 >>
提交
ec100a20
编写于
2月 28, 2017
作者:
K
Kamil Trzcinski
提交者:
Stan Hu
3月 01, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix concurrent access on builds/register
上级
ad00b9bc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
69 addition
and
12 deletion
+69
-12
app/services/ci/register_build_service.rb
app/services/ci/register_build_service.rb
+24
-12
spec/services/ci/register_build_service_spec.rb
spec/services/ci/register_build_service_spec.rb
+45
-0
未找到文件。
app/services/ci/register_build_service.rb
浏览文件 @
ec100a20
...
@@ -20,21 +20,33 @@ module Ci
...
@@ -20,21 +20,33 @@ module Ci
builds_for_specific_runner
builds_for_specific_runner
end
end
build
=
builds
.
find
do
|
build
|
valid
=
true
runner
.
can_pick?
(
build
)
end
if
build
builds
.
find
do
|
build
|
# In case when 2 runners try to assign the same build, second runner will be declined
next
unless
runner
.
can_pick?
(
build
)
# with StateMachines::InvalidTransition or StaleObjectError when doing run! or save method.
build
.
runner_id
=
runner
.
id
begin
build
.
run!
# In case when 2 runners try to assign the same build, second runner will be declined
end
# with StateMachines::InvalidTransition or StaleObjectError when doing run! or save method.
build
.
runner_id
=
runner
.
id
build
.
run!
Result
.
new
(
build
,
true
)
return
Result
.
new
(
build
,
true
)
rescue
StateMachines
::
InvalidTransition
,
ActiveRecord
::
StaleObjectError
# We are looping to find another build that is not conflicting
# It also indicates that this build can be picked and passed to runner.
# If we don't do it, basically a bunch of runners would be competing for a build
# and thus we will generate a lot of 409. This will increase
# the number of generated requests, also will reduce significantly
# how many builds can be picked by runner in a unit of time.
# In case we hit the concurrency-access lock,
# we still have to return 409 in the end,
# to make sure that this is properly handled by runner.
valid
=
false
end
end
rescue
StateMachines
::
InvalidTransition
,
ActiveRecord
::
StaleObjectError
Result
.
new
(
nil
,
valid
)
Result
.
new
(
build
,
false
)
end
end
private
private
...
...
spec/services/ci/register_build_service_spec.rb
浏览文件 @
ec100a20
...
@@ -170,6 +170,51 @@ module Ci
...
@@ -170,6 +170,51 @@ module Ci
end
end
end
end
context
'when first build is stalled'
do
before
do
pending_build
.
lock_version
=
10
end
subject
{
described_class
.
new
(
specific_runner
).
execute
}
context
'with multiple builds are in queue'
do
let!
(
:other_build
)
{
create
:ci_build
,
pipeline:
pipeline
}
before
do
allow_any_instance_of
(
Ci
::
RegisterBuildService
).
to
receive
(
:builds_for_specific_runner
)
.
and_return
([
pending_build
,
other_build
])
end
it
"receives second build from the queue"
do
expect
(
subject
).
to
be_valid
expect
(
subject
.
build
).
to
eq
(
other_build
)
end
end
context
'when single build is in queue'
do
before
do
allow_any_instance_of
(
Ci
::
RegisterBuildService
).
to
receive
(
:builds_for_specific_runner
)
.
and_return
([
pending_build
])
end
it
"does not receive any valid result"
do
expect
(
subject
).
not_to
be_valid
end
end
context
'when there is no build in queue'
do
before
do
allow_any_instance_of
(
Ci
::
RegisterBuildService
).
to
receive
(
:builds_for_specific_runner
)
.
and_return
([])
end
it
"does not receive builds but result is valid"
do
expect
(
subject
).
to
be_valid
expect
(
subject
.
build
).
to
be_nil
end
end
end
def
execute
(
runner
)
def
execute
(
runner
)
described_class
.
new
(
runner
).
execute
.
build
described_class
.
new
(
runner
).
execute
.
build
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录