<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../app/bootstrap.php';

use App\Controllers\Cron\ShipmentEngine;

// Avoid session warnings in CLI
if (php_sapi_name() === 'cli') {
    if (session_status() === PHP_SESSION_NONE) {
        session_start();
    }
}


$engine = new ShipmentEngine();
// echo $engine->processMovements();

while (true) {
    try {
        $engine->processMovements();
    } catch (\Throwable $e) {
        echo "[" . date('Y-m-d H:i:s') . "] Error: " . $e->getMessage() . "\n";
    }

    // Sleep for 10 seconds before the next run
    sleep(10);
}