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/CloudStorageHealthWorker.php

59 lines
2.0 KiB
PHTML

<?php
namespace App\Command;
use App\Services\Cloud\CloudObjectStorageHealthProbeService;
use App\Services\Cloud\CloudRuntimeHeartbeat;
/** Short periodic provider probes, intentionally isolated from replica copy. */
final class CloudStorageHealthWorker
{
public static function run(
array $argv = [],
?CloudRuntimeHeartbeat $heartbeat = null
): int {
$once = in_array('--once', $argv, true);
$heartbeat ??= CloudRuntimeHeartbeat::start('storage_health', $once);
$unresolved = false;
try {
$worker = new CloudObjectStorageHealthProbeService();
do {
$heartbeat->busy('storage_health_probe');
try {
$worked = $worker->tick();
$errors = $worker->observationErrors();
} catch (\Throwable $error) {
$errors = ['storage_health_failed'];
$heartbeat->error('storage_health_failed');
fwrite(STDERR, 'storage health worker temporarily unavailable: '
. get_class($error) . PHP_EOL);
if ($once) {
return 1;
}
$worked = false;
}
if ($errors === []) {
if ($worked) {
$unresolved = false;
$heartbeat->success();
} elseif (!$unresolved) {
$heartbeat->success();
}
} else {
$unresolved = true;
$heartbeat->error($errors[0]);
}
if (!$once && !$worked) {
usleep(1000000);
}
} while (!$once);
} catch (\Throwable $error) {
$heartbeat->error('storage_health_failed');
throw $error;
} finally {
$heartbeat->stopped();
}
return 0;
}
}