Skip to content

A platform for community discussion. Free, open, simple.

DEV: Log live slots of Sidekiq jobs (#28600)

Bianca Nenciu95b09dd77702
diff --git a/app/jobs/base.rb b/app/jobs/base.rb
index 419f1f58ad5..3d064048acb 100644
--- a/app/jobs/base.rb
+++ b/app/jobs/base.rb
@@ -136,12 +136,27 @@ module Jobs
@data["@timestamp"] = Time.now
@data["duration"] = current_duration if @data["status"] == "pending"
self.class.raw_log("#{@data.to_json}\n")
+
+ if live_slots_limit > 0 && @data["live_slots_start"].present? &&
+ @data["live_slots_finish"].present?
+ live_slots = @data["live_slots_finish"] - @data["live_slots_start"]
+
+ if live_slots >= live_slots_limit
+ Rails.logger.warn(
+ "Sidekiq Job '#{@data["job_name"]}' allocated #{live_slots} objects in the heap: #{@data.inspect}",
+ )
+ end
+ end
end
def enabled?
ENV["DISCOURSE_LOG_SIDEKIQ"] == "1"
end
+ def live_slots_limit
+ @live_slots_limit ||= ENV["DISCOURSE_LIVE_SLOTS_SIDEKIQ_LIMIT"].to_i
+ end
+
def self.mutex
@@mutex ||= Mutex.new
end