diff options
Diffstat (limited to 'config/initializers/sidekiq_cluster.rb')
-rw-r--r-- | config/initializers/sidekiq_cluster.rb | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/config/initializers/sidekiq_cluster.rb b/config/initializers/sidekiq_cluster.rb index 2f9c1de47eb..6fd598b3e25 100644 --- a/config/initializers/sidekiq_cluster.rb +++ b/config/initializers/sidekiq_cluster.rb @@ -9,22 +9,23 @@ if ENV['ENABLE_SIDEKIQ_CLUSTER'] 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. - if Process.ppid != parent - 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 + + 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 |