From 60affe23730f0ed4116c0293906f1c7b8cac5bfb Mon Sep 17 00:00:00 2001 From: Roberto Miranda Date: Thu, 15 Aug 2024 19:18:40 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=87=E2=80=8D=E2=99=80=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/promenade/periodic_stats.rb | 18 +++++++++--------- lib/promenade/pitchfork/stats.rb | 4 ++-- lib/promenade/raindrops/stats.rb | 1 - spec/promenade/pitchfork/stats_spec.rb | 1 - 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/promenade/periodic_stats.rb b/lib/promenade/periodic_stats.rb index bb3ab5d..be1459d 100644 --- a/lib/promenade/periodic_stats.rb +++ b/lib/promenade/periodic_stats.rb @@ -1,4 +1,4 @@ -require 'singleton' +require "singleton" module Promenade class PeriodicStats @@ -32,7 +32,7 @@ def start @thread_stopped = false @thread = Thread.new do - while active? do + while active? block.call sleep(frequency) # Ensure the sleep is inside the loop end @@ -55,14 +55,14 @@ def stop private - attr_reader :logger, :frequency, :block, :thread, :thread_stopped + attr_reader :logger, :frequency, :block, :thread, :thread_stopped - def started? - thread&.alive? - end + def started? + thread&.alive? + end - def active? - !thread_stopped - end + def active? + !thread_stopped + end end end diff --git a/lib/promenade/pitchfork/stats.rb b/lib/promenade/pitchfork/stats.rb index 1394897..d1f8dce 100644 --- a/lib/promenade/pitchfork/stats.rb +++ b/lib/promenade/pitchfork/stats.rb @@ -47,13 +47,13 @@ def self.instrument attr_reader :workers_count, :live_workers_count, :active_workers, :queued_requests def capacity - return 0 if live_workers_count.nil? || live_workers_count.zero? + return 0 if live_workers_count.nil? || live_workers_count == 0 live_workers_count - active_workers end def busy_percent - return 0 if live_workers_count.zero? + return 0 if live_workers_count == 0 (active_workers.to_f / live_workers_count) * 100 end diff --git a/lib/promenade/raindrops/stats.rb b/lib/promenade/raindrops/stats.rb index b1cbb86..6480731 100644 --- a/lib/promenade/raindrops/stats.rb +++ b/lib/promenade/raindrops/stats.rb @@ -15,7 +15,6 @@ module Raindrops end class Stats - attr_reader :active_workers, :queued_requests, :listener_address def initialize(listener_address: nil) diff --git a/spec/promenade/pitchfork/stats_spec.rb b/spec/promenade/pitchfork/stats_spec.rb index 37f9469..51aa049 100644 --- a/spec/promenade/pitchfork/stats_spec.rb +++ b/spec/promenade/pitchfork/stats_spec.rb @@ -50,4 +50,3 @@ end end end -