BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
14642e3c
Commit
14642e3c
authored
Apr 21, 2017
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor ExpirePipelineCacheWorker#perform
Make it gracefully handle unexisting pipelines and refactor iterating all the merge request paths.
parent
c623c41c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
13 deletions
+27
-13
expire_pipeline_cache_worker.rb
app/workers/expire_pipeline_cache_worker.rb
+11
-5
pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+10
-8
expire_pipeline_cache_worker_spec.rb
spec/workers/expire_pipeline_cache_worker_spec.rb
+6
-0
No files found.
app/workers/expire_pipeline_cache_worker.rb
View file @
14642e3c
...
...
@@ -3,14 +3,18 @@ class ExpirePipelineCacheWorker
include
PipelineQueue
def
perform
(
pipeline_id
)
pipeline
=
Ci
::
Pipeline
.
find
(
pipeline_id
)
pipeline
=
Ci
::
Pipeline
.
find_by
(
id:
pipeline_id
)
return
unless
pipeline
project
=
pipeline
.
project
store
=
Gitlab
::
EtagCaching
::
Store
.
new
store
.
touch
(
project_pipelines_path
(
project
))
store
.
touch
(
commit_pipelines_path
(
project
,
pipeline
.
commit
))
if
pipeline
.
commit
store
.
touch
(
new_merge_request_pipelines_path
(
project
))
merge_requests_pipelines_paths
(
project
,
pipeline
).
each
{
|
path
|
store
.
touch
(
path
)
}
each_pipelines_merge_request_path
(
project
,
pipeline
)
do
|
path
|
store
.
touch
(
path
)
end
Gitlab
::
Cache
::
Ci
::
ProjectPipelineStatus
.
update_for_pipeline
(
pipeline
)
end
...
...
@@ -39,13 +43,15 @@ class ExpirePipelineCacheWorker
format: :json
)
end
def
merge_requests_pipelines_paths
(
project
,
pipeline
)
pipeline
.
all_merge_requests
.
collect
do
|
merge_request
|
Gitlab
::
Routing
.
url_helpers
.
pipelines_namespace_project_merge_request_path
(
def
each_pipelines_merge_request_path
(
project
,
pipeline
)
pipeline
.
all_merge_requests
.
each
do
|
merge_request
|
path
=
Gitlab
::
Routing
.
url_helpers
.
pipelines_namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request
,
format: :json
)
yield
(
path
)
end
end
end
spec/models/ci/pipeline_spec.rb
View file @
14642e3c
...
...
@@ -1014,11 +1014,12 @@ describe Ci::Pipeline, models: true do
end
describe
"#merge_requests"
do
let
(
:project
)
{
create
(
:
project
,
:repository
)
}
let
(
:pipeline
)
{
FactoryGirl
.
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
'master'
,
sha:
project
.
repository
.
commit
(
'master'
).
id
)
}
let
(
:project
)
{
create
(
:
empty_project
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
'master'
,
sha:
'a288a022a53a5a944fae87bcec6efc87b7061808'
)
}
it
"returns merge requests whose `diff_head_sha` matches the pipeline's SHA"
do
merge_request
=
create
(
:merge_request
,
source_project:
project
,
source_branch:
pipeline
.
ref
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:diff_head_sha
)
{
'a288a022a53a5a944fae87bcec6efc87b7061808'
}
expect
(
pipeline
.
merge_requests
).
to
eq
([
merge_request
])
end
...
...
@@ -1038,23 +1039,24 @@ describe Ci::Pipeline, models: true do
end
describe
"#all_merge_requests"
do
let
(
:project
)
{
create
(
:
project
,
:repository
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
'master'
,
sha:
project
.
repository
.
commit
(
'master'
).
id
)
}
let
(
:project
)
{
create
(
:
empty_project
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
'master'
,
sha:
'a288a022a53a5a944fae87bcec6efc87b7061808'
)
}
it
"returns merge request
s whose `diff_head_sha` matches the pipeline's SHA
"
do
it
"returns merge request
if pipeline runs on `diff_head_sha`
"
do
merge_request
=
create
(
:merge_request
,
source_project:
project
,
source_branch:
pipeline
.
ref
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:diff_head_sha
)
{
'a288a022a53a5a944fae87bcec6efc87b7061808'
}
expect
(
pipeline
.
all_merge_requests
).
to
eq
([
merge_request
])
end
it
"returns merge requests whose source branch matches the pipeline's source branch"
do
pipeline
=
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
'master'
,
sha:
project
.
repository
.
commit
(
'master^'
).
id
)
it
"returns merge request if pipeline runs any commit of the `source_branch`"
do
merge_request
=
create
(
:merge_request
,
source_project:
project
,
source_branch:
pipeline
.
ref
)
allow_any_instance_of
(
MergeRequest
).
to
receive
(
:diff_head_sha
)
{
'97de212e80737a608d939f648d959671fb0a0142b'
}
expect
(
pipeline
.
all_merge_requests
).
to
eq
([
merge_request
])
end
it
"doesn't return merge request
s whose source branch doesn't match the pipeline's ref
"
do
it
"doesn't return merge request
if pipeline runs on a different `source_branch`
"
do
create
(
:merge_request
,
source_project:
project
,
source_branch:
'feature'
,
target_branch:
'master'
)
expect
(
pipeline
.
all_merge_requests
).
to
be_empty
...
...
spec/workers/expire_pipeline_cache_worker_spec.rb
View file @
14642e3c
...
...
@@ -29,6 +29,12 @@ describe ExpirePipelineCacheWorker do
subject
.
perform
(
pipeline
.
id
)
end
it
"doesn't do anything if the pipeline not exist"
do
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
not_to
receive
(
:touch
)
subject
.
perform
(
617748
)
end
it
'updates the cached status for a project'
do
expect
(
Gitlab
::
Cache
::
Ci
::
ProjectPipelineStatus
).
to
receive
(
:update_for_pipeline
).
with
(
pipeline
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment