#!/usr/bin/env php
<?php

declare(strict_types=1);

if (php_sapi_name() !== 'cli') {
    echo "CLI only\n";
    exit(1);
}

require dirname(__DIR__) . '/config/php-guard.php';
require dirname(__DIR__) . '/config/app.php';
require_once APP_ROOT . '/src/Admin/CatalogueController.php';
Database::reconnect();
@set_time_limit(0);
@ignore_user_abort(true);

// Drainers run in numbered slots, bounded by the same "Parallel" setting the video
// queue uses. A spawn for a slot that is already taken simply exits; claim() is
// safe under concurrency, so several drainers share one queue without colliding.
$slot = (int) ($argv[1] ?? 0);

GalleryImportQueue::drainSlot($slot);
