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
d35515cb
Commit
d35515cb
authored
Apr 24, 2017
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'tc-realtime-every-pipeline-on-mr' into 'master'
Properly expire cache for **all** MRs of a pipeline Closes #31040 See merge request !10770
parents
e2ff9406
95662468
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
54 deletions
+103
-54
pipeline.rb
app/models/ci/pipeline.rb
+10
-6
expire_pipeline_cache_worker.rb
app/workers/expire_pipeline_cache_worker.rb
+44
-38
tc-realtime-every-pipeline-on-mr.yml
changelogs/unreleased/tc-realtime-every-pipeline-on-mr.yml
+4
-0
pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+22
-4
expire_pipeline_cache_worker_spec.rb
spec/workers/expire_pipeline_cache_worker_spec.rb
+23
-6
No files found.
app/models/ci/pipeline.rb
View file @
d35515cb
...
...
@@ -84,24 +84,23 @@ module Ci
end
after_transition
[
:created
,
:pending
]
=>
:running
do
|
pipeline
|
pipeline
.
run_after_commit
{
PipelineMetricsWorker
.
perform_async
(
id
)
}
pipeline
.
run_after_commit
{
PipelineMetricsWorker
.
perform_async
(
pipeline
.
id
)
}
end
after_transition
any
=>
[
:success
]
do
|
pipeline
|
pipeline
.
run_after_commit
{
PipelineMetricsWorker
.
perform_async
(
id
)
}
pipeline
.
run_after_commit
{
PipelineMetricsWorker
.
perform_async
(
pipeline
.
id
)
}
end
after_transition
[
:created
,
:pending
,
:running
]
=>
:success
do
|
pipeline
|
pipeline
.
run_after_commit
{
PipelineSuccessWorker
.
perform_async
(
id
)
}
pipeline
.
run_after_commit
{
PipelineSuccessWorker
.
perform_async
(
pipeline
.
id
)
}
end
after_transition
do
|
pipeline
,
transition
|
next
if
transition
.
loopback?
pipeline
.
run_after_commit
do
PipelineHooksWorker
.
perform_async
(
id
)
Ci
::
ExpirePipelineCacheService
.
new
(
project
,
nil
)
.
execute
(
pipeline
)
PipelineHooksWorker
.
perform_async
(
pipeline
.
id
)
ExpirePipelineCacheWorker
.
perform_async
(
pipeline
.
id
)
end
end
...
...
@@ -389,6 +388,11 @@ module Ci
.
select
{
|
merge_request
|
merge_request
.
head_pipeline
.
try
(
:id
)
==
self
.
id
}
end
# All the merge requests for which the current pipeline runs/ran against
def
all_merge_requests
@all_merge_requests
||=
project
.
merge_requests
.
where
(
source_branch:
ref
)
end
def
detailed_status
(
current_user
)
Gitlab
::
Ci
::
Status
::
Pipeline
::
Factory
.
new
(
self
,
current_user
)
...
...
app/
services/ci/expire_pipeline_cache_service
.rb
→
app/
workers/expire_pipeline_cache_worker
.rb
View file @
d35515cb
module
Ci
class
ExpirePipelineCacheService
<
BaseService
attr_reader
:pipeline
def
execute
(
pipeline
)
@pipeline
=
pipeline
store
=
Gitlab
::
EtagCaching
::
Store
.
new
class
ExpirePipelineCacheWorker
include
Sidekiq
::
Worker
include
PipelineQueue
def
perform
(
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
))
each_pipelines_merge_request_path
(
project
,
pipeline
)
do
|
path
|
store
.
touch
(
path
)
end
store
.
touch
(
project_pipelines_path
)
store
.
touch
(
commit_pipelines_path
)
if
pipeline
.
commit
store
.
touch
(
new_merge_request_pipelines_path
)
merge_requests_pipelines_paths
.
each
{
|
path
|
store
.
touch
(
path
)
}
Gitlab
::
Cache
::
Ci
::
ProjectPipelineStatus
.
update_for_pipeline
(
pipeline
)
end
Gitlab
::
Cache
::
Ci
::
ProjectPipelineStatus
.
update_for_pipeline
(
@pipeline
)
end
private
private
def
project_pipelines_path
(
project
)
Gitlab
::
Routing
.
url_helpers
.
namespace_project_pipelines_path
(
project
.
namespace
,
project
,
format: :json
)
end
def
project_pipelines_path
Gitlab
::
Routing
.
url_helpers
.
namespace_project_pipelines_path
(
project
.
namespace
,
project
,
format: :json
)
end
def
commit_pipelines_path
(
project
,
commit
)
Gitlab
::
Routing
.
url_helpers
.
pipelines_namespace_project_commit_path
(
project
.
namespace
,
project
,
commit
.
id
,
format: :json
)
end
def
commit_pipelines_path
Gitlab
::
Routing
.
url_helpers
.
pipelines_namespace_project_commit_path
(
project
.
namespace
,
project
,
pipeline
.
commit
.
id
,
format: :json
)
end
def
new_merge_request_pipelines_path
(
project
)
Gitlab
::
Routing
.
url_helpers
.
new_namespace_project_merge_request_path
(
project
.
namespace
,
project
,
format: :json
)
end
def
new_merge_request_pipelines_path
Gitlab
::
Routing
.
url_helpers
.
new_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
)
end
def
merge_requests_pipelines_paths
pipeline
.
merge_requests
.
collect
do
|
merge_request
|
Gitlab
::
Routing
.
url_helpers
.
pipelines_namespace_project_merge_request_path
(
project
.
namespace
,
project
,
merge_request
,
format: :json
)
end
yield
(
path
)
end
end
end
changelogs/unreleased/tc-realtime-every-pipeline-on-mr.yml
0 → 100644
View file @
d35515cb
---
title
:
Properly expire cache for all MRs of a pipeline
merge_request
:
10770
author
:
spec/models/ci/pipeline_spec.rb
View file @
d35515cb
...
...
@@ -400,8 +400,8 @@ describe Ci::Pipeline, models: true do
end
describe
'pipeline caching'
do
it
'
executes ExpirePipelinesCacheService
'
do
expect
_any_instance_of
(
Ci
::
ExpirePipelineCacheService
).
to
receive
(
:execute
).
with
(
pipeline
)
it
'
performs ExpirePipelinesCacheWorker
'
do
expect
(
ExpirePipelineCacheWorker
).
to
receive
(
:perform_async
).
with
(
pipeline
.
id
)
pipeline
.
cancel
end
...
...
@@ -1039,11 +1039,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
...
...
@@ -1062,6 +1063,23 @@ describe Ci::Pipeline, models: true do
end
end
describe
"#all_merge_requests"
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
'master'
)
}
it
"returns all merge requests having the same source branch"
do
merge_request
=
create
(
:merge_request
,
source_project:
project
,
source_branch:
pipeline
.
ref
)
expect
(
pipeline
.
all_merge_requests
).
to
eq
([
merge_request
])
end
it
"doesn't return merge requests having 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
end
end
describe
'#stuck?'
do
before
do
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
...
...
spec/
services/ci/expire_pipeline_cache_service
_spec.rb
→
spec/
workers/expire_pipeline_cache_worker
_spec.rb
View file @
d35515cb
require
'spec_helper'
describe
Ci
::
ExpirePipelineCacheService
,
services:
true
do
describe
ExpirePipelineCacheWorker
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
subject
{
described_class
.
new
(
project
,
user
)
}
subject
{
described_class
.
new
}
describe
'#
execute
'
do
it
'invalidate Etag caching for project pipelines path'
do
describe
'#
perform
'
do
it
'invalidate
s
Etag caching for project pipelines path'
do
pipelines_path
=
"/
#{
project
.
full_path
}
/pipelines.json"
new_mr_pipelines_path
=
"/
#{
project
.
full_path
}
/merge_requests/new.json"
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
pipelines_path
)
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
new_mr_pipelines_path
)
subject
.
execute
(
pipeline
)
subject
.
perform
(
pipeline
.
id
)
end
it
'invalidates Etag caching for merge request pipelines if pipeline runs on any commit of that source branch'
do
pipeline
=
create
(
:ci_empty_pipeline
,
status:
'created'
,
project:
project
,
ref:
'master'
)
merge_request
=
create
(
:merge_request
,
source_project:
project
,
source_branch:
pipeline
.
ref
)
merge_request_pipelines_path
=
"/
#{
project
.
full_path
}
/merge_requests/
#{
merge_request
.
iid
}
/pipelines.json"
allow_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
)
expect_any_instance_of
(
Gitlab
::
EtagCaching
::
Store
).
to
receive
(
:touch
).
with
(
merge_request_pipelines_path
)
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
)
subject
.
execute
(
pipeline
)
subject
.
perform
(
pipeline
.
id
)
end
end
end
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