<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;

final class DistributedWorkersHeartbeatCommand extends AbstractCommand
{
    public function name(): string { return 'distributed:workers:heartbeat'; }
    public function description(): string { return 'PPphp Distributed Worker Heartbeat'; }

    public function handle(array $arguments = []): int
    {
        $this->title('PPphp Distributed Worker Heartbeat');
        $coordinator = \PpPhp\Core\Platform\Event\Distributed\DistributedRuntimeCoordinator::instance(\PpPhp\Core\Platform\Console\ConsolePath::basePath()); if ($coordinator->registry()->count() === 0) { $coordinator->registerWorker('distributed_console_worker', 'console_node', 1); } $ok = $coordinator->heartbeat('console_node', 'distributed_console_worker', \PpPhp\Core\Platform\Event\Distributed\DistributedWorkerRecord::BUSY, 1); $this->line('Heartbeat: ' . ($ok ? 'YES' : 'NO'));
        return 0;
    }
}
