From 6ef1aff99132595cfc07ea021be4bba38f57fde8 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 16 May 2024 09:56:38 +0200 Subject: [PATCH] Refactor scheduling of container status and log drain checks --- app/Console/Kernel.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 51e4cfc17..dfbcf7870 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -18,6 +18,7 @@ use App\Models\Team; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; +use Illuminate\Support\Sleep; class Kernel extends ConsoleKernel { @@ -76,13 +77,24 @@ private function check_resources($schedule) $containerServers = $servers->where('settings.is_swarm_worker', false)->where('settings.is_build_server', false); } foreach ($containerServers as $server) { - $schedule->job(new ContainerStatusJob($server))->everyMinute()->onOneServer(); + $schedule->job(new ContainerStatusJob($server))->everyTwoMinutes()->onOneServer()->before(function () { + $wait = rand(5, 20); + ray('waiting for ' . $wait . ' seconds'); + Sleep::for($wait)->seconds(); + ray('waited for ' . $wait . ' seconds'); + }); if ($server->isLogDrainEnabled()) { - $schedule->job(new CheckLogDrainContainerJob($server))->everyMinute()->onOneServer(); + $schedule->job(new CheckLogDrainContainerJob($server))->everyTwoMinutes()->onOneServer()->before(function () { + $wait = rand(5, 20); + Sleep::for($wait)->seconds(); + }); } } foreach ($servers as $server) { - $schedule->job(new ServerStatusJob($server))->everyMinute()->onOneServer(); + $schedule->job(new ServerStatusJob($server))->everyTwoMinutes()->onOneServer()->before(function () { + $wait = rand(5, 20); + Sleep::for($wait)->seconds(); + }); } } private function instance_auto_update($schedule)