<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;

final class DistributedQueueDispatchCommand extends AbstractCommand
{
    public function name(): string { return 'distributed:queue:dispatch'; }
    public function description(): string { return 'PPphp Distributed Queue Dispatch'; }

    public function handle(array $arguments = []): int
    {
        $this->title('PPphp Distributed Queue Dispatch');
        $base = \PpPhp\Core\Platform\Console\ConsolePath::basePath(); $runtime = \PpPhp\Core\Platform\Event\Distributed\DistributedRuntimeCoordinator::instance($base); if ($runtime->registry()->count() === 0) { $runtime->registerWorker('distributed_console_worker', 'console_node', 1); } $manager = \PpPhp\Core\Platform\Event\Distributed\Queue\DistributedQueueCoordinator::instance($base); if ($manager->registry()->get('console.queue') === null) { $manager->registerQueue('console.queue', 1); } $result = $manager->dispatch('console.queue', 'console.job.' . time(), 60); $this->line('Dispatched: ' . (($result['dispatched'] ?? false) ? 'YES' : 'NO')); if (($result['leaseId'] ?? '') !== '') { $this->line('Lease: ' . $result['leaseId']); }
        return 0;
    }
}
