<?php
// usage:
//   php __CRON/cron_ikev2_vpnid_sync_retry_cli.php
//   php __CRON/cron_ikev2_vpnid_sync_retry_cli.php --limit=50

@chdir(__DIR__ . '/..');

include_once(__DIR__ . '/../_common.php');
include_once(G5_PATH . '/mylib/ikev2_provision.lib.php');

$limit = 50;
foreach ($argv as $arg) {
    if (strpos($arg, '--limit=') === 0) {
        $v = (int)substr($arg, 8);
        if ($v > 0) {
            $limit = $v;
        }
    }
}

$ret = vpnlink_vpnid_sync_retry_due_jobs($limit);

$out = array(
    'ok' => true,
    'processed' => (int)$ret['processed'],
    'success' => (int)$ret['success'],
    'fail' => (int)$ret['fail'],
    'limit' => $limit,
    'ts' => date('Y-m-d H:i:s')
);

echo json_encode($out, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL;
