Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
056f1b70
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,发现更多精彩内容 >>
提交
056f1b70
编写于
2月 14, 2017
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify implementation of pipeline retry service
上级
94495f98
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
41 addition
and
60 deletion
+41
-60
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+1
-7
app/services/ci/retry_pipeline_service.rb
app/services/ci/retry_pipeline_service.rb
+5
-37
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+4
-4
spec/services/ci/retry_pipeline_service_spec.rb
spec/services/ci/retry_pipeline_service_spec.rb
+31
-12
未找到文件。
app/models/ci/pipeline.rb
浏览文件 @
056f1b70
...
...
@@ -214,13 +214,7 @@ module Ci
def
cancel_running
Gitlab
::
OptimisticLocking
.
retry_lock
(
statuses
.
cancelable
)
do
|
cancelable
|
cancelable
.
each
do
|
status
|
if
status
.
created?
status
.
skip
elsif
status
.
active?
status
.
cancel
end
end
cancelable
.
find_each
(
&
:cancel
)
end
end
...
...
app/services/ci/retry_pipeline_service.rb
浏览文件 @
056f1b70
module
Ci
class
RetryPipelineService
<
::
BaseService
def
execute
(
pipeline
)
@pipeline
=
pipeline
unless
can?
(
current_user
,
:update_pipeline
,
pipeline
)
raise
Gitlab
::
Access
::
AccessDeniedError
end
pipeline
.
mark_as_processable_after_stage
(
resume_stage
.
index
)
each_build
(
pipeline
.
builds
.
failed_or_canceled
)
do
|
build
|
next
unless
build
.
retryable?
retryable_builds_in_subsequent_stages
do
|
build
|
Ci
::
RetryBuildService
.
new
(
project
,
current_user
)
.
reprocess
(
build
)
end
retryable_builds_in_first_unsuccessful_stage
do
|
build
|
Ci
::
RetryBuildService
.
new
(
project
,
current_user
)
.
retry
(
build
)
end
pipeline
.
process!
end
private
def
retryable_builds_in_subsequent_stages
relation
=
@pipeline
.
builds
.
after_stage
(
resume_stage
.
index
)
.
failed_or_canceled
each_retryable_build_with_locking
(
relation
)
do
|
build
|
yield
build
end
end
def
retryable_builds_in_first_unsuccessful_stage
relation
=
resume_stage
.
builds
.
failed_or_canceled
each_retryable_build_with_locking
(
relation
)
do
|
build
|
yield
build
end
end
def
each_retryable_build_with_locking
(
relation
)
def
each_build
(
relation
)
Gitlab
::
OptimisticLocking
.
retry_lock
(
relation
)
do
|
builds
|
builds
.
find_each
do
|
build
|
next
unless
build
.
retryable?
yield
build
end
end
end
def
resume_stage
@resume_stage
||=
@pipeline
.
stages
.
find
do
|
stage
|
stage
.
failed?
||
stage
.
canceled?
builds
.
find_each
{
|
build
|
yield
build
}
end
end
end
...
...
spec/models/ci/pipeline_spec.rb
浏览文件 @
056f1b70
...
...
@@ -766,8 +766,8 @@ describe Ci::Pipeline, models: true do
pipeline
.
cancel_running
end
it
'
skip
s created builds'
do
expect
(
latest_status
).
to
eq
[
'canceled'
,
'
skipp
ed'
]
it
'
cancel
s created builds'
do
expect
(
latest_status
).
to
eq
[
'canceled'
,
'
cancel
ed'
]
end
end
end
...
...
@@ -801,7 +801,7 @@ describe Ci::Pipeline, models: true do
end
it
'retries both builds'
do
expect
(
latest_status
).
to
contain_exactly
(
'pending'
,
'
pending
'
)
expect
(
latest_status
).
to
contain_exactly
(
'pending'
,
'
created
'
)
end
end
...
...
@@ -814,7 +814,7 @@ describe Ci::Pipeline, models: true do
end
it
'retries both builds'
do
expect
(
latest_status
).
to
contain_exactly
(
'pending'
,
'
pending
'
)
expect
(
latest_status
).
to
contain_exactly
(
'pending'
,
'
created
'
)
end
end
end
...
...
spec/services/ci/retry_pipeline_service_spec.rb
浏览文件 @
056f1b70
...
...
@@ -11,9 +11,9 @@ describe Ci::RetryPipelineService, '#execute', :services do
context
'when there are failed builds in the last stage'
do
before
do
create_build
(
name:
'rspec 1'
,
status: :success
,
stage_num:
0
)
create_build
(
name:
'rspec 2'
,
status: :failed
,
stage_num:
1
)
create_build
(
name:
'rspec 3'
,
status: :canceled
,
stage_num:
1
)
create_build
(
'rspec 1'
,
:success
,
0
)
create_build
(
'rspec 2'
,
:failed
,
1
)
create_build
(
'rspec 3'
,
:canceled
,
1
)
end
it
'enqueues all builds in the last stage'
do
...
...
@@ -27,10 +27,10 @@ describe Ci::RetryPipelineService, '#execute', :services do
context
'when there are failed or canceled builds in the first stage'
do
before
do
create_build
(
name:
'rspec 1'
,
status: :failed
,
stage_num:
0
)
create_build
(
name:
'rspec 2'
,
status: :canceled
,
stage_num:
0
)
create_build
(
name:
'rspec 3'
,
status: :skipped
,
stage_num:
1
)
create_build
(
name:
'deploy 1'
,
status: :skipped
,
stage_num:
2
)
create_build
(
'rspec 1'
,
:failed
,
0
)
create_build
(
'rspec 2'
,
:canceled
,
0
)
create_build
(
'rspec 3'
,
:canceled
,
1
)
create_build
(
'deploy 1'
,
:canceled
,
2
)
end
it
'retries builds failed builds and marks subsequent for processing'
do
...
...
@@ -46,10 +46,10 @@ describe Ci::RetryPipelineService, '#execute', :services do
context
'when there is failed build present which was run on failure'
do
before
do
create_build
(
name:
'rspec 1'
,
status: :failed
,
stage_num:
0
)
create_build
(
name:
'rspec 2'
,
status: :canceled
,
stage_num:
0
)
create_build
(
name:
'rspec 3'
,
status: :skipped
,
stage_num:
1
)
create_build
(
name:
'report 1'
,
status: :failed
,
stage_num:
2
)
create_build
(
'rspec 1'
,
:failed
,
0
)
create_build
(
'rspec 2'
,
:canceled
,
0
)
create_build
(
'rspec 3'
,
:canceled
,
1
)
create_build
(
'report 1'
,
:failed
,
2
)
end
it
'retries builds failed builds and marks subsequent for processing'
do
...
...
@@ -65,9 +65,27 @@ describe Ci::RetryPipelineService, '#execute', :services do
it
'creates a new job for report job in this case'
do
service
.
execute
(
pipeline
)
# TODO, expect to be_retried
expect
(
statuses
.
where
(
name:
'report 1'
).
count
).
to
eq
2
end
end
context
'when there is canceled manual build in first stage'
do
before
do
create_build
(
'rspec 1'
,
:failed
,
0
)
create_build
(
'staging'
,
:canceled
,
0
,
:manual
)
create_build
(
'rspec 2'
,
:canceled
,
1
)
end
it
'retries builds failed builds and marks subsequent for processing'
do
service
.
execute
(
pipeline
)
expect
(
build
(
'rspec 1'
)).
to
be_pending
expect
(
build
(
'staging'
)).
to
be_skipped
expect
(
build
(
'rspec 2'
)).
to
be_created
expect
(
pipeline
.
reload
).
to
be_running
end
end
end
context
'when user is not allowed to retry pipeline'
do
...
...
@@ -85,11 +103,12 @@ describe Ci::RetryPipelineService, '#execute', :services do
statuses
.
latest
.
find_by
(
name:
name
)
end
def
create_build
(
name
:,
status
:,
stage_num
:
)
def
create_build
(
name
,
status
,
stage_num
,
on
=
'on_success'
)
create
(
:ci_build
,
name:
name
,
status:
status
,
stage:
"stage_
#{
stage_num
}
"
,
stage_idx:
stage_num
,
when:
on
,
pipeline:
pipeline
)
do
|
build
|
pipeline
.
update_status
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录