Lines
100.00%
22 / 22
Methods
100.00%
3 / 3
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| buildWorkerStatuses | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| buildWorkerStatus | 100.00% | 20 / 20 | 100.00% | 1 / 1 | 4 | ||
| 15 | final readonly class WorkerStatusBuilder | |
| 16 | { | |
| 17 | public function __construct( | |
| 18 | private WorkerSlotRegistry $slots, | |
| 19 | private WorkerWatchdog $watchdog, | |
| 20 | private WorkerRestartPolicy $restartPolicy, | |
| 21 | private HaCallSlots $callSlots, | |
| 22 | ) {} | |
| 23 | ||
| 24 | /** @return list<WorkerStatus> */ | |
| 25 | public function buildWorkerStatuses(): array | |
| 26 | { | |
| 27 | return array_map($this->buildWorkerStatus(...), $this->slots->listSlotStates()); | |
| 28 | } | |
| 29 | ||
| 30 | private function buildWorkerStatus(WorkerSlotState $state): WorkerStatus | |
| 31 | { | |
| 32 | $workerId = $state->slot->workerId; | |
| 33 | $live = $state->phase === WorkerPhase::Live ? $state->handle : null; | |
| 34 | $pong = $live?->lastPong; | |
| 35 | ||
| 36 | return new WorkerStatus( | |
| 37 | workerId: $workerId->value, | |
| 38 | phase: $state->phase, | |
| 39 | appIds: $state->slot->listAppIds()->toStrings(), | |
| 40 | pid: $live?->getPid(), | |
| 41 | ready: $live?->isReady() ?? false, | |
| 42 | missedProbes: $live === null ? 0 : $this->watchdog->countMissedProbes($live), | |
| 43 | loopLag: $pong?->loopLag, | |
| 44 | memoryBytes: $pong?->memoryBytes, | |
| 45 | lastPongAt: $live?->lastPongAt, | |
| 46 | restartsInWindow: $this->restartPolicy->countRestartsInWindow($workerId), | |
| 47 | restartDueAt: $state->restartDueAt, | |
| 48 | outbox: $state->getOutboxStatus(), | |
| 49 | inFlightServiceCalls: $live === null ? 0 : $this->callSlots->countInFlightCallsFor($live), | |
| 50 | restarts: $state->restarts, | |
| 51 | quarantines: $state->quarantines, | |
| 52 | ); | |
| 53 | } | |
| 54 | } |