summaryrefslogtreecommitdiff
path: root/app/workers/jira_connect/retry_request_worker.rb
blob: b0f6dada6394bf64b262780004f12a7290a582b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

module JiraConnect
  class RetryRequestWorker # rubocop:disable Scalability/IdempotentWorker
    include ApplicationWorker

    data_consistency :always
    queue_namespace :jira_connect
    feature_category :integrations
    urgency :low

    worker_has_external_dependencies!

    def perform(proxy_url, jwt, attempts = 3)
      r = Gitlab::HTTP.post(proxy_url, headers: { 'Authorization' => "JWT #{jwt}" })

      self.class.perform_in(1.hour, proxy_url, jwt, attempts - 1) if r.code >= 400 && attempts > 0
    rescue *Gitlab::HTTP::HTTP_ERRORS
      self.class.perform_in(1.hour, proxy_url, jwt, attempts - 1) if attempts > 0
    end
  end
end