mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Revert "Revert "Revert "FIX: Heartbeat check per sidekiq process (#7873)"""
This reverts commit c3497559be.
This commit is contained in:
@@ -11,7 +11,6 @@ class Demon::Base
|
||||
|
||||
def self.start(count = 1, verbose: false)
|
||||
@demons ||= {}
|
||||
before_start(count)
|
||||
count.times do |i|
|
||||
(@demons["#{prefix}_#{i}"] ||= new(i, verbose: verbose)).start
|
||||
end
|
||||
@@ -38,10 +37,7 @@ class Demon::Base
|
||||
end
|
||||
end
|
||||
|
||||
def self.before_start(count)
|
||||
end
|
||||
|
||||
attr_reader :pid, :parent_pid, :started, :index, :identifier
|
||||
attr_reader :pid, :parent_pid, :started, :index
|
||||
attr_accessor :stop_timeout
|
||||
|
||||
def initialize(index, rails_root: nil, parent_pid: nil, verbose: false)
|
||||
|
||||
@@ -3,38 +3,6 @@
|
||||
require "demon/base"
|
||||
|
||||
class Demon::Sidekiq < Demon::Base
|
||||
RANDOM_HEX = SecureRandom.hex
|
||||
QUEUE_IDS = []
|
||||
|
||||
def self.queues_last_heartbeat_hash_key
|
||||
@@queues_last_heartbeat_hash_key ||= "#{RANDOM_HEX}_queues_last_heartbeat_hash"
|
||||
end
|
||||
|
||||
def self.trigger_heartbeat(name)
|
||||
$redis.hset(queues_last_heartbeat_hash_key, name, Time.new.to_i.to_s)
|
||||
extend_expiry(queues_last_heartbeat_hash_key)
|
||||
end
|
||||
|
||||
def self.get_queue_last_heartbeat(name)
|
||||
extend_expiry(queues_last_heartbeat_hash_key)
|
||||
$redis.hget(queues_last_heartbeat_hash_key, name).to_i
|
||||
end
|
||||
|
||||
def self.clear_heartbeat_queues!
|
||||
$redis.del(queues_last_heartbeat_hash_key)
|
||||
end
|
||||
|
||||
def self.before_start(count)
|
||||
# cleans up heartbeat queues from previous boot up
|
||||
Sidekiq::Queue.all.each { |queue| queue.clear if queue.name[/^\h{32}$/] }
|
||||
count.times do
|
||||
QUEUE_IDS << SecureRandom.hex
|
||||
end
|
||||
end
|
||||
|
||||
def self.extend_expiry(key)
|
||||
$redis.expire(key, 60 * 60)
|
||||
end
|
||||
|
||||
def self.prefix
|
||||
"sidekiq"
|
||||
@@ -44,11 +12,6 @@ class Demon::Sidekiq < Demon::Base
|
||||
blk ? (@blk = blk) : @blk
|
||||
end
|
||||
|
||||
def run
|
||||
@identifier = QUEUE_IDS[@index]
|
||||
super
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def suppress_stdout
|
||||
@@ -73,7 +36,7 @@ class Demon::Sidekiq < Demon::Base
|
||||
|
||||
options = ["-c", GlobalSetting.sidekiq_workers.to_s]
|
||||
|
||||
[['critical', 8], [@identifier, 8], ['default', 4], ['low', 2], ['ultra_low', 1]].each do |queue_name, weight|
|
||||
[['critical', 8], ['default', 4], ['low', 2], ['ultra_low', 1]].each do |queue_name, weight|
|
||||
custom_queue_hostname = ENV["UNICORN_SIDEKIQ_#{queue_name.upcase}_QUEUE_HOSTNAME"]
|
||||
|
||||
if !custom_queue_hostname || custom_queue_hostname.split(',').include?(`hostname`.strip)
|
||||
|
||||
Reference in New Issue
Block a user