2018-06-27 07:23:28 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-18 19:26:56 +00:00
|
|
|
class ExpirePipelineCacheWorker
|
2017-11-28 16:08:30 +00:00
|
|
|
include ApplicationWorker
|
2017-04-18 19:26:56 +00:00
|
|
|
include PipelineQueue
|
|
|
|
|
2017-11-28 16:16:50 +00:00
|
|
|
queue_namespace :pipeline_cache
|
2017-08-21 12:02:20 +00:00
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-04-20 06:44:01 +00:00
|
|
|
def perform(pipeline_id)
|
2017-04-21 15:39:19 +00:00
|
|
|
pipeline = Ci::Pipeline.find_by(id: pipeline_id)
|
|
|
|
return unless pipeline
|
|
|
|
|
2017-04-18 19:26:56 +00:00
|
|
|
project = pipeline.project
|
|
|
|
store = Gitlab::EtagCaching::Store.new
|
|
|
|
|
|
|
|
store.touch(project_pipelines_path(project))
|
2017-05-20 22:07:36 +00:00
|
|
|
store.touch(project_pipeline_path(project, pipeline))
|
2017-12-05 13:15:30 +00:00
|
|
|
store.touch(commit_pipelines_path(project, pipeline.commit)) unless pipeline.commit.nil?
|
2017-04-18 19:26:56 +00:00
|
|
|
store.touch(new_merge_request_pipelines_path(project))
|
2017-04-21 15:39:19 +00:00
|
|
|
each_pipelines_merge_request_path(project, pipeline) do |path|
|
|
|
|
store.touch(path)
|
|
|
|
end
|
2017-04-18 19:26:56 +00:00
|
|
|
|
|
|
|
Gitlab::Cache::Ci::ProjectPipelineStatus.update_for_pipeline(pipeline)
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-04-18 19:26:56 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def project_pipelines_path(project)
|
2017-06-29 17:06:35 +00:00
|
|
|
Gitlab::Routing.url_helpers.project_pipelines_path(project, format: :json)
|
2017-04-18 19:26:56 +00:00
|
|
|
end
|
|
|
|
|
2017-05-20 22:07:36 +00:00
|
|
|
def project_pipeline_path(project, pipeline)
|
2017-06-29 17:06:35 +00:00
|
|
|
Gitlab::Routing.url_helpers.project_pipeline_path(project, pipeline, format: :json)
|
2017-05-20 22:07:36 +00:00
|
|
|
end
|
|
|
|
|
2017-04-18 19:26:56 +00:00
|
|
|
def commit_pipelines_path(project, commit)
|
2017-06-29 17:06:35 +00:00
|
|
|
Gitlab::Routing.url_helpers.pipelines_project_commit_path(project, commit.id, format: :json)
|
2017-04-18 19:26:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new_merge_request_pipelines_path(project)
|
2017-06-29 17:06:35 +00:00
|
|
|
Gitlab::Routing.url_helpers.project_new_merge_request_path(project, format: :json)
|
2017-04-18 19:26:56 +00:00
|
|
|
end
|
|
|
|
|
2017-04-21 15:39:19 +00:00
|
|
|
def each_pipelines_merge_request_path(project, pipeline)
|
|
|
|
pipeline.all_merge_requests.each do |merge_request|
|
2017-06-29 17:06:35 +00:00
|
|
|
path = Gitlab::Routing.url_helpers.pipelines_project_merge_request_path(project, merge_request, format: :json)
|
2017-04-21 15:39:19 +00:00
|
|
|
|
|
|
|
yield(path)
|
2017-04-18 19:26:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|