|
|
|
|
<?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(200);
|
|
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
}
|