summaryrefslogtreecommitdiff
path: root/app/workers
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2017-04-18 21:26:56 +0200
committerToon Claes <toon@gitlab.com>2017-04-24 10:07:01 +0200
commitccb9beeed0e418ef4dea201b3507bd2f4a14b4a2 (patch)
treeff75331541746d5ab9e27d9151cbccdae214fb43 /app/workers
parentf07edb5af1e18be817e49e0afd86f59a6eef1cd9 (diff)
downloadgitlab-ce-ccb9beeed0e418ef4dea201b3507bd2f4a14b4a2.tar.gz
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.
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/expire_pipeline_cache_worker.rb51
1 files changed, 51 insertions, 0 deletions
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