Lines 100.00% 7 / 7
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
TriggerRejections 100.00% 7 / 7 100.00% 2 / 2 4 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 refuseSubscribers 100.00% 6 / 6 100.00% 1 / 1 3
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Broker\Trigger;
6
7use Stewart\Runtime\Broker\SubscriptionRegistry;
8use Stewart\Runtime\Broker\WorkerSlotRegistry;
9use Stewart\Runtime\Ipc\Message\SubscriptionAck;
10use Stewart\Runtime\Model\SubscriptionKind;
11use Stewart\Support\Wire\TriggerSpec;
12
13final readonly class TriggerRejections
14{
15    public function __construct(
16        private SubscriptionRegistry $registry,
17        private WorkerSlotRegistry $slots,
18    ) {}
19
20    public function refuseSubscribers(TriggerSpec $spec, string $reason): void
21    {
22        $routes = $this->registry->findRoutes(SubscriptionKind::Trigger, $spec->getSharingKey());
23
24        foreach ($routes->listWorkerIds() as $workerId) {
25            $handle = $this->slots->findHandleForWorker($workerId);
26
27            foreach ($routes->listSubscriptionIdsForWorker($workerId) as $subscriptionId) {
28                $handle?->send(new SubscriptionAck($subscriptionId, false, $reason));
29                $this->registry->remove($subscriptionId);
30            }
31        }
32    }
33}