Refactor scheduling of container status and log drain checks

This commit is contained in:
Andras Bacsai 2024-05-16 09:56:38 +02:00
parent 57a026a7a1
commit 6ef1aff991

View File

@ -18,6 +18,7 @@
use App\Models\Team; use App\Models\Team;
use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Sleep;
class Kernel extends ConsoleKernel 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); $containerServers = $servers->where('settings.is_swarm_worker', false)->where('settings.is_build_server', false);
} }
foreach ($containerServers as $server) { 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()) { 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) { 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) private function instance_auto_update($schedule)