From ccb9beeed0e418ef4dea201b3507bd2f4a14b4a2 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Tue, 18 Apr 2017 21:26:56 +0200 Subject: Properly expire cache for **all** MRs of a pipeline Turn ExpirePipelineCacheService into Worker so it can fetch all the merge requests for which the pipeline runs or did run against. --- app/workers/expire_pipeline_cache_worker.rb | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 app/workers/expire_pipeline_cache_worker.rb (limited to 'app/workers') diff --git a/app/workers/expire_pipeline_cache_worker.rb b/app/workers/expire_pipeline_cache_worker.rb new file mode 100644 index 00000000000..65e7b091506 --- /dev/null +++ b/app/workers/expire_pipeline_cache_worker.rb @@ -0,0 +1,51 @@ +class ExpirePipelineCacheWorker + include Sidekiq::Worker + include PipelineQueue + + def perform(id) + pipeline = Ci::Pipeline.find(id) + 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) } + + Gitlab::Cache::Ci::ProjectPipelineStatus.update_for_pipeline(pipeline) + end + + private + + def project_pipelines_path(project) + 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 new_merge_request_pipelines_path(project) + Gitlab::Routing.url_helpers.new_namespace_project_merge_request_path( + project.namespace, + project, + 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( + project.namespace, + project, + merge_request, + format: :json) + end + end +end -- cgit v1.2.3