Lines
100.00%
12 / 12
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| PausedAppsSync | 100.00% | 12 / 12 | 100.00% | 2 / 2 | 6 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| applyPausedAppIds | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 5 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Worker; | |
| 6 | ||
| 7 | use Stewart\Contracts\App\Collection\AppIdCollection; | |
| 8 | use Stewart\Runtime\Scope\ScopeLifecycle; | |
| 9 | ||
| 10 | final readonly class PausedAppsSync | |
| 11 | { | |
| 12 | public function __construct( | |
| 13 | private AppLifecycle $apps, | |
| 14 | private AppResources $resources, | |
| 15 | private ScopeLifecycle $scopes, | |
| 16 | private WorkerLogger $logger, | |
| 17 | ) {} | |
| 18 | ||
| 19 | public function applyPausedAppIds(AppIdCollection $pausedAppIds): void | |
| 20 | { | |
| 21 | foreach ($this->apps->listSlots() as $slot) { | |
| 22 | $scope = $slot->scope(); | |
| 23 | $scopeState = $this->scopes->findOrCreateStateOf($scope); | |
| 24 | ||
| 25 | if ($scopeState->isClosed()) { | |
| 26 | continue; | |
| 27 | } | |
| 28 | ||
| 29 | $shouldPause = $pausedAppIds->containsId($slot->id()); | |
| 30 | ||
| 31 | if ($shouldPause === $scopeState->isPaused()) { | |
| 32 | continue; | |
| 33 | } | |
| 34 | ||
| 35 | if ($shouldPause) { | |
| 36 | $this->resources->pauseScope($scope); | |
| 37 | $this->logger->forScope($scope)->info('App paused'); | |
| 38 | } else { | |
| 39 | $this->resources->resumeScope($scope); | |
| 40 | $this->logger->forScope($scope)->info('App resumed'); | |
| 41 | } | |
| 42 | } | |
| 43 | } | |
| 44 | } |