From 2832e2389317e872ec914692477a0059560390b0 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Tue, 21 Jul 2020 03:54:34 +0000 Subject: [PATCH] refactor: convert heartbeat event handlers to console commands --- console-commands/gk/flush-metrics.php | 9 +++++++++ console-commands/gk/ping-endpoints.php | 9 +++++++++ .../Gatekeeper/heartbeat/40_flush-metrics.php | 7 ------- .../Gatekeeper/heartbeat/50_ping-endpoints.php | 3 --- php-classes/Gatekeeper/Endpoints/Pinger.php | 14 +++++++++----- 5 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 console-commands/gk/flush-metrics.php create mode 100644 console-commands/gk/ping-endpoints.php delete mode 100644 event-handlers/Gatekeeper/heartbeat/40_flush-metrics.php delete mode 100644 event-handlers/Gatekeeper/heartbeat/50_ping-endpoints.php diff --git a/console-commands/gk/flush-metrics.php b/console-commands/gk/flush-metrics.php new file mode 100644 index 0000000..76a36fd --- /dev/null +++ b/console-commands/gk/flush-metrics.php @@ -0,0 +1,9 @@ +info('Flushing metrics'); + +$flushed = Gatekeeper\Metrics\Metrics::flushMetricSamples(); + +$logger->info("{$flushed} metrics flushed"); diff --git a/console-commands/gk/ping-endpoints.php b/console-commands/gk/ping-endpoints.php new file mode 100644 index 0000000..0d3ea18 --- /dev/null +++ b/console-commands/gk/ping-endpoints.php @@ -0,0 +1,9 @@ +info('Pinging endpoints...'); + +$pinged = Gatekeeper\Endpoints\Pinger::pingOverdueEndpoints($logger); + +$logger->info("{$pinged} endpoints pinged"); diff --git a/event-handlers/Gatekeeper/heartbeat/40_flush-metrics.php b/event-handlers/Gatekeeper/heartbeat/40_flush-metrics.php deleted file mode 100644 index 6a3f9bf..0000000 --- a/event-handlers/Gatekeeper/heartbeat/40_flush-metrics.php +++ /dev/null @@ -1,7 +0,0 @@ -PingFrequency*60 < time()-$lastPing['time'] ) { - static::pingEndpoint($Endpoint, $verbose); + static::pingEndpoint($Endpoint, $logger); } } + + return count($endpoints); } - public static function pingEndpoint(Endpoint $Endpoint, $verbose = false) + public static function pingEndpoint(Endpoint $Endpoint, LoggerInterface $logger = null) { - $verbose && printf('Testing endpoint: /%s...', $Endpoint->Path) && flush(); + $logger && $logger->info("/{$Endpoint->Path} is being pinged"); // execute and capture request @@ -108,7 +112,7 @@ public static function pingEndpoint(Endpoint $Endpoint, $verbose = false) } - $verbose && printf("%s\n", $testPassed ? 'passed' : 'failed') && flush(); + $logger && $logger->info("/{$Endpoint->Path} ". ($testPassed ? 'passed' : 'failed')); // cache result and timestamp