# typed: ignore # Copyright (c) 2015 Sqreen. All Rights Reserved. # Please refer to our terms for more information: https://www.sqreen.com/terms.html module Sqreen module WebServer module Puma def self.active? Sqreen::Dependency.const_exist?('Puma::Runner') && ObjectSpace.each_object(::Puma::Runner).count > 0 end def forking? !cluster.nil? end def preload_app? forking? && (cluster && cluster.preload? || false) end def master? # HACK: expects outside calling timimg # - with preloading, this is hit early in master and records its PID # - without preloading but forking, the app will be loaded in the child, so recorded PID stays nil # - without forking, master makes no sense, recorded PID stays nil master! if preload_app? Sqreen.log.debug "[#{Process.pid}] master? #{@master_pid == Process.pid}" @master_pid == Process.pid end def before_fork before_fork = lambda do |_ = nil| # 3.x sends an arg but <3.0 doesn't yield end (configuration.options[:before_fork] || []) << before_fork end def after_fork after_fork = lambda do |_| yield end (configuration.options[:before_worker_boot] ||= []) << after_fork end private def master! @master_pid ||= Process.pid end def cluster return unless ::Puma.const_defined?('Cluster') ObjectSpace.each_object(::Puma::Cluster).first end def configuration ObjectSpace.each_object(::Puma::Configuration).first end end end end