Lines 0.00% 0 / 14
Functions and Methods 0.00% 0 / 3
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
WorkerReadyHandler 0.00% 0 / 14 0.00% 0 / 3 12 0.00% 0 / 1
 __construct 0.00% 0 / 1 0.00% 0 / 1 2
 handledMessageClass 0.00% 0 / 1 0.00% 0 / 1 2
 handle 0.00% 0 / 12 0.00% 0 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Broker\Message;
6
7use Psr\Log\LoggerInterface;
8use Stewart\Contracts\App\AppId;
9use Stewart\Runtime\Broker\Exposure\ExposureReconciler;
10use Stewart\Runtime\Broker\WorkerHandle;
11use Stewart\Runtime\Broker\WorkerPool;
12use Stewart\Runtime\Ipc\Message\WorkerMessage;
13use Stewart\Runtime\Ipc\Message\WorkerReady;
14
15/** @implements WorkerMessageHandler<WorkerReady> */
16final readonly class WorkerReadyHandler implements WorkerMessageHandler
17{
18    public function __construct(
19        private WorkerPool $pool,
20        private ExposureReconciler $reconciler,
21        private LoggerInterface $logger,
22    ) {}
23
24    public function handledMessageClass(): string
25    {
26        return WorkerReady::class;
27    }
28
29    /** @param WorkerReady $message */
30    public function handle(WorkerHandle $handle, WorkerMessage $message): void
31    {
32        $this->pool->markReady($handle);
33        $this->reconciler->recordWorkerReady(
34            $handle->id,
35            $message->appIds->collection->filter(static fn(AppId $appId): bool => !$message->failedAppIds->collection->containsId($appId)),
36        );
37
38        $this->logger->info('Worker ready', [
39            'worker' => $handle->id->value,
40            'pid' => $handle->getPid(),
41            'apps' => $message->appIds->collection->toStrings(),
42            'failed' => $message->failedAppIds->collection->toStrings(),
43            'memory_mb' => round($message->memoryBytes / 1048576, 1),
44        ]);
45    }
46}