Welcome to mirror list, hosted at ThFree Co, Russian Federation.

close_incident_worker.rb « incident_management « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 011cb76442b56e955b9f2d677024941248f1a2a5 (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
# frozen_string_literal: true

module IncidentManagement
  class CloseIncidentWorker
    include ApplicationWorker

    idempotent!
    deduplicate :until_executed
    data_consistency :always
    feature_category :incident_management
    urgency :low

    # Issues:CloseService execute webhooks which are treated as external dependencies
    worker_has_external_dependencies!

    def perform(issue_id)
      incident = Issue.with_issue_type(:incident).opened.find_by_id(issue_id)

      return unless incident

      close_incident(incident)
      add_system_note(incident)
    end

    private

    def user
      @user ||= Users::Internal.alert_bot
    end

    def close_incident(incident)
      ::Issues::CloseService
        .new(container: incident.project, current_user: user)
        .execute(incident, system_note: false)
    end

    def add_system_note(incident)
      return unless incident.reset.closed?

      SystemNoteService.auto_resolve_prometheus_alert(incident, incident.project, user)
    end
  end
end