Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
9082d1e0
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,发现更多精彩内容 >>
提交
9082d1e0
编写于
3月 30, 2017
作者:
B
Bob Van Landuyt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename Ci::PipelineStatus -> Ci::ProjectBuildStatus
上级
2d246df5
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
102 addition
and
93 deletion
+102
-93
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+1
-1
app/models/ci/pipeline_status.rb
app/models/ci/pipeline_status.rb
+0
-86
app/models/project.rb
app/models/project.rb
+1
-1
lib/gitlab/cache/ci/project_build_status.rb
lib/gitlab/cache/ci/project_build_status.rb
+90
-0
spec/helpers/ci_status_helper_spec.rb
spec/helpers/ci_status_helper_spec.rb
+5
-1
spec/lib/gitlab/cache/ci/project_build_status_spec.rb
spec/lib/gitlab/cache/ci/project_build_status_spec.rb
+1
-1
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+3
-2
spec/models/project_spec.rb
spec/models/project_spec.rb
+1
-1
未找到文件。
app/models/ci/pipeline.rb
浏览文件 @
9082d1e0
...
...
@@ -394,7 +394,7 @@ module Ci
end
def
refresh_build_status_cache
Ci
::
Pipeline
Status
.
new
(
project
,
sha:
sha
,
status:
status
).
store_in_cache_if_needed
Gitlab
::
Cache
::
Ci
::
ProjectBuild
Status
.
new
(
project
,
sha:
sha
,
status:
status
).
store_in_cache_if_needed
end
private
...
...
app/models/ci/pipeline_status.rb
已删除
100644 → 0
浏览文件 @
2d246df5
# This class is not backed by a table in the main database.
# It loads the latest Pipeline for the HEAD of a repository, and caches that
# in Redis.
module
Ci
class
PipelineStatus
attr_accessor
:sha
,
:status
,
:project
,
:loaded
delegate
:commit
,
to: :project
def
self
.
load_for_project
(
project
)
new
(
project
).
tap
do
|
status
|
status
.
load_status
end
end
def
initialize
(
project
,
sha:
nil
,
status:
nil
)
@project
=
project
@sha
=
sha
@status
=
status
end
def
has_status?
loaded?
&&
sha
.
present?
&&
status
.
present?
end
def
load_status
return
if
loaded?
if
has_cache?
load_from_cache
else
load_from_commit
store_in_cache
end
self
.
loaded
=
true
end
def
load_from_commit
return
unless
commit
self
.
sha
=
commit
.
sha
self
.
status
=
commit
.
status
end
# We only cache the status for the HEAD commit of a project
# This status is rendered in project lists
def
store_in_cache_if_needed
return
unless
sha
return
delete_from_cache
unless
commit
store_in_cache
if
commit
.
sha
==
self
.
sha
end
def
load_from_cache
Gitlab
::
Redis
.
with
do
|
redis
|
self
.
sha
,
self
.
status
=
redis
.
hmget
(
cache_key
,
:sha
,
:status
)
end
end
def
store_in_cache
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
mapped_hmset
(
cache_key
,
{
sha:
sha
,
status:
status
})
end
end
def
delete_from_cache
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
del
(
cache_key
)
end
end
def
has_cache?
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
exists
(
cache_key
)
end
end
def
loaded?
self
.
loaded
end
def
cache_key
"projects/
#{
project
.
id
}
/build_status"
end
end
end
app/models/project.rb
浏览文件 @
9082d1e0
...
...
@@ -1197,7 +1197,7 @@ class Project < ActiveRecord::Base
end
def
pipeline_status
@pipeline_status
||=
Ci
::
Pipeline
Status
.
load_for_project
(
self
)
@pipeline_status
||=
Gitlab
::
Cache
::
Ci
::
ProjectBuild
Status
.
load_for_project
(
self
)
end
def
mark_import_as_failed
(
error_message
)
...
...
lib/gitlab/cache/ci/project_build_status.rb
0 → 100644
浏览文件 @
9082d1e0
# This class is not backed by a table in the main database.
# It loads the latest Pipeline for the HEAD of a repository, and caches that
# in Redis.
module
Gitlab
module
Cache
module
Ci
class
ProjectBuildStatus
attr_accessor
:sha
,
:status
,
:project
,
:loaded
delegate
:commit
,
to: :project
def
self
.
load_for_project
(
project
)
new
(
project
).
tap
do
|
status
|
status
.
load_status
end
end
def
initialize
(
project
,
sha:
nil
,
status:
nil
)
@project
=
project
@sha
=
sha
@status
=
status
end
def
has_status?
loaded?
&&
sha
.
present?
&&
status
.
present?
end
def
load_status
return
if
loaded?
if
has_cache?
load_from_cache
else
load_from_commit
store_in_cache
end
self
.
loaded
=
true
end
def
load_from_commit
return
unless
commit
self
.
sha
=
commit
.
sha
self
.
status
=
commit
.
status
end
# We only cache the status for the HEAD commit of a project
# This status is rendered in project lists
def
store_in_cache_if_needed
return
unless
sha
return
delete_from_cache
unless
commit
store_in_cache
if
commit
.
sha
==
self
.
sha
end
def
load_from_cache
Gitlab
::
Redis
.
with
do
|
redis
|
self
.
sha
,
self
.
status
=
redis
.
hmget
(
cache_key
,
:sha
,
:status
)
end
end
def
store_in_cache
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
mapped_hmset
(
cache_key
,
{
sha:
sha
,
status:
status
})
end
end
def
delete_from_cache
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
del
(
cache_key
)
end
end
def
has_cache?
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
exists
(
cache_key
)
end
end
def
loaded?
self
.
loaded
end
def
cache_key
"projects/
#{
project
.
id
}
/build_status"
end
end
end
end
end
spec/helpers/ci_status_helper_spec.rb
浏览文件 @
9082d1e0
...
...
@@ -19,7 +19,11 @@ describe CiStatusHelper do
describe
"#pipeline_status_cache_key"
do
it
"builds a cache key for pipeline status"
do
pipeline_status
=
Ci
::
PipelineStatus
.
new
(
build
(
:project
),
sha:
"123abc"
,
status:
"success"
)
pipeline_status
=
Gitlab
::
Cache
::
Ci
::
ProjectBuildStatus
.
new
(
build
(
:project
),
sha:
"123abc"
,
status:
"success"
)
expect
(
helper
.
pipeline_status_cache_key
(
pipeline_status
)).
to
eq
(
"pipeline-status/123abc-success"
)
end
end
...
...
spec/
models/ci/pipeline
_status_spec.rb
→
spec/
lib/gitlab/cache/ci/project_build
_status_spec.rb
浏览文件 @
9082d1e0
require
'spec_helper'
describe
Ci
::
Pipeline
Status
do
describe
Gitlab
::
Cache
::
Ci
::
ProjectBuild
Status
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:pipeline_status
)
{
described_class
.
new
(
project
)
}
...
...
spec/models/ci/pipeline_spec.rb
浏览文件 @
9082d1e0
...
...
@@ -1084,8 +1084,9 @@ describe Ci::Pipeline, models: true do
it
'updates the cached status'
do
fake_status
=
double
# after updating the status, the status is set to `skipped` for this pipeline's builds
expect
(
Ci
::
PipelineStatus
).
to
receive
(
:new
).
with
(
pipeline
.
project
,
sha:
'123456'
,
status:
'skipped'
).
and_return
(
fake_status
)
expect
(
Gitlab
::
Cache
::
Ci
::
ProjectBuildStatus
).
to
receive
(
:new
).
with
(
pipeline
.
project
,
sha:
'123456'
,
status:
'skipped'
).
and_return
(
fake_status
)
expect
(
fake_status
).
to
receive
(
:store_in_cache_if_needed
)
pipeline
.
update_status
...
...
spec/models/project_spec.rb
浏览文件 @
9082d1e0
...
...
@@ -1949,7 +1949,7 @@ describe Project, models: true do
describe
'#pipeline_status'
do
let
(
:project
)
{
create
(
:project
)
}
it
'builds a pipeline status'
do
expect
(
project
.
pipeline_status
).
to
be_a
(
Ci
::
Pipeline
Status
)
expect
(
project
.
pipeline_status
).
to
be_a
(
Gitlab
::
Cache
::
Ci
::
ProjectBuild
Status
)
end
it
'hase a loaded pipeline status'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录