2019-07-08 21:06:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-17 11:09:10 -04:00
|
|
|
if ENV['ENABLE_SIDEKIQ_CLUSTER']
|
2019-07-08 15:46:34 -04:00
|
|
|
Thread.new do
|
|
|
|
Thread.current.abort_on_exception = true
|
|
|
|
|
|
|
|
parent = Process.ppid
|
|
|
|
|
|
|
|
loop do
|
|
|
|
sleep(5)
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
if Process.ppid != parent
|
|
|
|
Process.kill(:TERM, Process.pid)
|
2020-04-08 14:09:16 -04:00
|
|
|
|
2020-07-31 08:10:02 -04:00
|
|
|
# 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)
|
2020-04-08 14:09:16 -04:00
|
|
|
|
|
|
|
# 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)
|
2019-07-08 15:46:34 -04:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|