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