summaryrefslogtreecommitdiff
path: root/app/workers/expire_pipeline_cache_worker.rb
blob: 3e34de22c192796965ccf9f3f94fdd24b4d617b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class ExpirePipelineCacheWorker
  include ApplicationWorker
  include PipelineQueue

  queue_namespace :pipeline_cache

  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))
    store.touch(commit_pipelines_path(project, pipeline.commit)) if pipeline.commit
    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

  private

  def project_pipelines_path(project)
    Gitlab::Routing.url_helpers.project_pipelines_path(project, format: :json)
  end

  def project_pipeline_path(project, pipeline)
    Gitlab::Routing.url_helpers.project_pipeline_path(project, pipeline, format: :json)
  end

  def commit_pipelines_path(project, commit)
    Gitlab::Routing.url_helpers.pipelines_project_commit_path(project, commit.id, format: :json)
  end

  def new_merge_request_pipelines_path(project)
    Gitlab::Routing.url_helpers.project_new_merge_request_path(project, format: :json)
  end

  def each_pipelines_merge_request_path(project, pipeline)
    pipeline.all_merge_requests.each do |merge_request|
      path = Gitlab::Routing.url_helpers.pipelines_project_merge_request_path(project, merge_request, format: :json)

      yield(path)
    end
  end
end