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

sidekiq_cluster.rb « initializers « config - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6fd598b3e2529428b1ee1aee32d49d46e17bbf23 (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

if ENV['ENABLE_SIDEKIQ_CLUSTER']
  Thread.new do
    Thread.current.abort_on_exception = true

    parent = Process.ppid

    loop do
      sleep(5)

      next if Process.ppid == parent

      # In cluster mode it's possible that the master process is SIGKILL'd. In
      # this case the parent PID changes and we need to terminate ourselves.

      Process.kill(:TERM, Process.pid)

      # Allow sidekiq to cleanly terminate and push any running jobs back
      # into the queue.  We use the configured timeout and add a small
      # grace period
      sleep(Sidekiq.options[:timeout] + 5)

      # Signaling the Sidekiq Pgroup as KILL is not forwarded to
      # a possible child process. In Sidekiq Cluster, all child Sidekiq
      # processes are PGROUP leaders (each process has its own pgroup).
      Process.kill(:KILL, 0)
      break
    end
  end
end