<?php

declare(strict_types=1);

require_once dirname(__DIR__) . '/system/bootstrap.php';

$limit = 25;
$timeout = 5;
$pendingOnly = false;
foreach (array_slice($argv, 1) as $arg) {
    if (str_starts_with($arg, '--limit=')) {
        $limit = max(1, (int) substr($arg, 8));
        continue;
    }
    if (str_starts_with($arg, '--timeout=')) {
        $timeout = max(1, (int) substr($arg, 10));
        continue;
    }
    if ($arg === '--pending-only') {
        $pendingOnly = true;
    }
}

$result = myronRunCoordinatedPublicPageCacheWarmFailSoft($limit, $timeout, !$pendingOnly);
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL;
exit(!empty($result['ok']) ? 0 : 1);
