summaryrefslogtreecommitdiff
path: root/app/workers/web_hooks/destroy_worker.rb
blob: b92fe86bafb12506a1f48a2405d4ff7f5bfdb8b6 (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
# frozen_string_literal: true

module WebHooks
  class DestroyWorker
    include ApplicationWorker

    data_consistency :always
    sidekiq_options retry: 3
    feature_category :integrations
    tags :exclude_from_kubernetes
    urgency :low

    idempotent!

    def perform(user_id, web_hook_id)
      user = User.find_by_id(user_id)
      hook = WebHook.find_by_id(web_hook_id)

      return unless user && hook

      result = ::WebHooks::DestroyService.new(user).sync_destroy(hook)

      return result if result[:status] == :success

      e = ::WebHooks::DestroyService::DestroyError.new(result[:message])
      Gitlab::ErrorTracking.track_exception(e, web_hook_id: hook.id)

      raise e
    end
  end
end