Commit 7f334035 authored by Yorick Peterse's avatar Yorick Peterse

Refactor ExpirePipelineCacheWorker for EE

This refactors ExpirePipelineCacheWorker so that EE can more easily
extend its logic, without having to inject code in the middle of a CE
method.
parent fc8d41f2
...@@ -11,23 +11,9 @@ class ExpirePipelineCacheWorker ...@@ -11,23 +11,9 @@ class ExpirePipelineCacheWorker
pipeline = Ci::Pipeline.find_by(id: pipeline_id) pipeline = Ci::Pipeline.find_by(id: pipeline_id)
return unless pipeline return unless pipeline
project = pipeline.project
store = Gitlab::EtagCaching::Store.new store = Gitlab::EtagCaching::Store.new
store.touch(project_pipelines_path(project)) update_etag_cache(pipeline, store)
store.touch(project_pipeline_path(project, pipeline))
store.touch(commit_pipelines_path(project, pipeline.commit)) unless pipeline.commit.nil?
store.touch(new_merge_request_pipelines_path(project))
each_pipelines_merge_request_path(project, pipeline) do |path|
store.touch(path)
end
triggered_by = pipeline.triggered_by_pipeline
store.touch(project_pipeline_path(triggered_by.project, triggered_by)) if triggered_by
pipeline.triggered_pipelines.each do |triggered|
store.touch(project_pipeline_path(triggered.project, triggered))
end
Gitlab::Cache::Ci::ProjectPipelineStatus.update_for_pipeline(pipeline) Gitlab::Cache::Ci::ProjectPipelineStatus.update_for_pipeline(pipeline)
end end
...@@ -58,4 +44,25 @@ class ExpirePipelineCacheWorker ...@@ -58,4 +44,25 @@ class ExpirePipelineCacheWorker
yield(path) yield(path)
end end
end end
# Updates ETag caches of a pipeline.
#
# This logic resides in a separate method so that EE can more easily extend
# it.
#
# @param [Ci::Pipeline] pipeline
# @param [Gitlab::EtagCaching::Store] store
def update_etag_cache(pipeline, store)
project = pipeline.project
store.touch(project_pipelines_path(project))
store.touch(project_pipeline_path(project, pipeline))
store.touch(commit_pipelines_path(project, pipeline.commit)) unless pipeline.commit.nil?
store.touch(new_merge_request_pipelines_path(project))
each_pipelines_merge_request_path(project, pipeline) do |path|
store.touch(path)
end
end
end end
ExpirePipelineCacheWorker.prepend(EE::ExpirePipelineCacheWorker)
# frozen_string_literal: true
module EE
module ExpirePipelineCacheWorker
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
override :update_etag_cache
def update_etag_cache(pipeline, store)
super
triggered_by = pipeline.triggered_by_pipeline
store.touch(project_pipeline_path(triggered_by.project, triggered_by)) if triggered_by
pipeline.triggered_pipelines.each do |triggered|
store.touch(project_pipeline_path(triggered.project, triggered))
end
end
end
end
ExpirePipelineCacheWorker.prepend(EE::ExpirePipelineCacheWorker)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment