debian-mirror-gitlab/config/initializers/sidekiq_cluster.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
886 B
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
2020-04-08 14:13:33 +05:30
if ENV['ENABLE_SIDEKIQ_CLUSTER']
2019-09-30 21:07:59 +05:30
Thread.new do
Thread.current.abort_on_exception = true
parent = Process.ppid
loop do
sleep(5)
2022-10-11 01:57:18 +05:30
next if Process.ppid == parent
2019-09-30 21:07:59 +05:30
# 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.
2022-10-11 01:57:18 +05:30
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
2023-01-13 00:05:48 +05:30
sleep(Sidekiq[:timeout] + 5)
2022-10-11 01:57:18 +05:30
# 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
2019-09-30 21:07:59 +05:30
end
end
end