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

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

module Gitlab
  # NotifyUponDeath can be included into a worker class if it should
  # notify any JobWaiter instances upon being moved to the Sidekiq dead queue.
  #
  # Note that this will only notify the waiter upon graceful termination, a
  # SIGKILL will still result in the waiter _not_ being notified.
  #
  # Workers including this module must have jobs passed where the last
  # argument is the key to notify, as a String.
  module NotifyUponDeath
    extend ActiveSupport::Concern

    included do
      # If a job is being exhausted we still want to notify the
      # Gitlab::Import::AdvanceStageWorker. This prevents the entire import from getting stuck
      # just because 1 job threw too many errors.
      sidekiq_retries_exhausted do |job|
        args = job['args']
        jid = job['jid']

        if args.length == 3 && (key = args.last) && key.is_a?(String)
          JobWaiter.notify(key, jid)
        end
      end
    end
  end
end