<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Console\Commands;

use PpPhp\Core\Platform\Console\AbstractCommand;

final class WorkerHeartbeatListCommand extends AbstractCommand
{
    public function name(): string { return 'worker:heartbeat:list'; }
    public function description(): string { return 'PPphp Worker Heartbeat List'; }

    public function handle(array $arguments = []): int
    {
        $this->title('PPphp Worker Heartbeat List');
        $manager = \PpPhp\Core\Platform\Event\Worker\Monitoring\WorkerHeartbeatManager::instance(\PpPhp\Core\Platform\Console\ConsolePath::basePath()); $manager->hydrate(); if ($manager->collection()->count() === 0) { $manager->record('worker_console_heartbeat', 'idle'); $manager->save(); } foreach ($manager->collection()->toArray() as $heartbeat) { $this->line('- ' . $heartbeat['workerId'] . ' ' . $heartbeat['status'] . ' handled=' . $heartbeat['handled'] . ' at=' . $heartbeat['recordedAt']); }
        return 0;
    }
}
