Lines 100.00% 15 / 15
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ScheduleStatusBuilder 100.00% 15 / 15 100.00% 2 / 2 5 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 buildScheduleStatuses 100.00% 14 / 14 100.00% 1 / 1 4
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Control\Assembler;
6
7use Stewart\Runtime\Broker\WorkerSlotRegistry;
8use Stewart\Runtime\Control\Protocol\Status\ScheduleStatus;
9
10final readonly class ScheduleStatusBuilder
11{
12    public function __construct(private WorkerSlotRegistry $slots) {}
13
14    /** @return list<ScheduleStatus> */
15    public function buildScheduleStatuses(): array
16    {
17        $statuses = [];
18
19        foreach ($this->slots->listLiveHandles() as $handle) {
20            foreach ($handle->lastPong->apps ?? [] as $app) {
21                foreach ($app->scheduleReports as $report) {
22                    $statuses[] = new ScheduleStatus(
23                        appId: $app->scope->wireValue(),
24                        workerId: $handle->id->value,
25                        taskId: $report->taskId,
26                        description: $report->description,
27                        nextRunAt: $report->nextRunAt,
28                        lastRunAt: $report->lastRunAt,
29                    );
30                }
31            }
32        }
33
34        usort($statuses, static fn(ScheduleStatus $a, ScheduleStatus $b): int => $a->workerId <=> $b->workerId);
35
36        return $statuses;
37    }
38}