You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/app/Command/CloudLifecycle.php

43 lines
1.4 KiB
PHP

<?php
namespace App\Command;
use App\Services\Cloud\CloudLifecycleService;
use App\Services\Cloud\CloudRuntimeHeartbeat;
final class CloudLifecycle
{
public static function run(array $argv = [], ?CloudRuntimeHeartbeat $heartbeat = null): int
{
$once = in_array('--once', $argv, true);
$heartbeat ??= CloudRuntimeHeartbeat::start('lifecycle', $once);
try {
$service = new CloudLifecycleService($heartbeat);
do {
$heartbeat->busy('lifecycle_tick');
try {
$service->tick();
$errors = $service->observationErrors();
if ($errors === []) {
$heartbeat->success();
} else {
$heartbeat->error($errors[0]);
}
} catch (\Throwable $error) {
$heartbeat->error('lifecycle_tick_failed');
fwrite(STDERR, 'cloud lifecycle temporarily unavailable: '
. get_class($error) . PHP_EOL);
if ($once) {
return 1;
}
}
if (!$once) {
usleep(15000000);
}
} while (!$once);
} finally {
$heartbeat->stopped();
}
return 0;
}
}