Make seeding Phase 3 — its own operator-triggered phase, not the tail of an onboard

Onboard now ends at Phase 2: connected, running, and saying so. Phase 3 sets the seeding gate posture and dispatches the seed. With MEDIA_SEED_ENABLED false there is no Phase 3 and the model is two phases.
This commit is contained in:
Gmer4Lfe
2026-08-17 10:23:03 -04:00
parent 427a31cdff
commit 7c957d96be
4 changed files with 207 additions and 139 deletions
+12 -5
View File
@@ -242,7 +242,7 @@ function vv_pt_remote_system(string $ip, string $sshKey): array {
//
// Returns [] when there has never been a seed. A stale "running" record whose pid is gone is
// reported as stopped rather than running: a record is not a process.
function vv_pt_media_seed(): array {
function vv_pt_media_seed(array $setupDb = [], string $nodeIdUpper = ''): array {
$stat = '/var/log/varaverk/Rsync/media_seed.json';
$log = '/var/log/varaverk/Rsync/media_seed.log';
@@ -257,10 +257,16 @@ function vv_pt_media_seed(): array {
$toggle = vv_arr_scalar($raw, 'MEDIA_SEED_ENABLED');
$enabled = ($toggle === '' || strtolower($toggle) === 'true');
if (!is_file($stat)) return ['enabled' => $enabled];
// Phase 3 is complete only when every share landed, which media_seed.sh decides and records
// at the end of a run that may have taken weeks. The job record cannot answer this: it goes
// "ok" the moment the process exits, including the exits that seeded nothing.
$phase3Done = $nodeIdUpper !== ''
&& ($setupDb[$nodeIdUpper . '_PHASE3_DONE'] ?? '') === 'true';
if (!is_file($stat)) return ['enabled' => $enabled, 'phase3_done' => $phase3Done];
$j = json_decode((string)file_get_contents($stat), true);
if (!is_array($j)) return ['enabled' => $enabled];
if (!is_array($j)) return ['enabled' => $enabled, 'phase3_done' => $phase3Done];
$status = (string)($j['status'] ?? '');
$pid = (int)($j['pid'] ?? 0);
@@ -292,7 +298,8 @@ function vv_pt_media_seed(): array {
}
return array_filter([
'enabled' => $enabled,
'enabled' => $enabled,
'phase3_done' => $phase3Done,
'status' => $status,
'start' => isset($j['start']) ? (int)$j['start'] : null,
'end' => isset($j['end']) ? (int)$j['end'] : null,
@@ -433,7 +440,7 @@ function vv_pt_nodes(): array {
'api_key_set' => $apiKeySet,
'api_key_preview' => $apiKeyPreview,
'metrics' => $metrics,
'media_seed' => $isMe ? [] : vv_pt_media_seed(),
'media_seed' => $isMe ? [] : vv_pt_media_seed($setupDb, $nodeIdUpper),
];
}
return $nodes;