2018-11-08 19:23:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class ExpirePipelineCacheWorker
|
2018-03-17 18:26:18 +05:30
|
|
|
include ApplicationWorker
|
2017-08-17 22:00:37 +05:30
|
|
|
include PipelineQueue
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
queue_namespace :pipeline_cache
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
def perform(pipeline_id)
|
|
|
|
pipeline = Ci::Pipeline.find_by(id: pipeline_id)
|
|
|
|
return unless pipeline
|
|
|
|
|
|
|
|
store = Gitlab::EtagCaching::Store.new
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
update_etag_cache(pipeline, store)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
Gitlab::Cache::Ci::ProjectPipelineStatus.update_for_pipeline(pipeline)
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def project_pipelines_path(project)
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::Routing.url_helpers.project_pipelines_path(project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def project_pipeline_path(project, pipeline)
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::Routing.url_helpers.project_pipeline_path(project, pipeline, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def commit_pipelines_path(project, commit)
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::Routing.url_helpers.pipelines_project_commit_path(project, commit.id, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def new_merge_request_pipelines_path(project)
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::Routing.url_helpers.project_new_merge_request_path(project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def each_pipelines_merge_request_path(project, pipeline)
|
|
|
|
pipeline.all_merge_requests.each do |merge_request|
|
2017-09-10 17:25:29 +05:30
|
|
|
path = Gitlab::Routing.url_helpers.pipelines_project_merge_request_path(project, merge_request, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
yield(path)
|
|
|
|
end
|
|
|
|
end
|
2019-03-02 22:35:43 +05:30
|
|
|
|
|
|
|
# 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
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|