debian-mirror-gitlab/app/workers/expire_pipeline_cache_worker.rb

55 lines
1.7 KiB
Ruby
Raw Normal View History

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
project = pipeline.project
store = Gitlab::EtagCaching::Store.new
store.touch(project_pipelines_path(project))
store.touch(project_pipeline_path(project, pipeline))
2018-03-17 18:26:18 +05:30
store.touch(commit_pipelines_path(project, pipeline.commit)) unless pipeline.commit.nil?
2017-08-17 22:00:37 +05:30
store.touch(new_merge_request_pipelines_path(project))
each_pipelines_merge_request_path(project, pipeline) do |path|
store.touch(path)
end
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
end