Lines
100.00%
13 / 13
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ReloadApplier | 100.00% | 13 / 13 | 100.00% | 2 / 2 | 3 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| applyReload | 100.00% | 12 / 12 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Broker\Reload; | |
| 6 | ||
| 7 | use Psr\Log\LoggerInterface; | |
| 8 | use Stewart\Runtime\App\AppDefinition; | |
| 9 | use Stewart\Runtime\App\CatalogWarnings; | |
| 10 | use Stewart\Runtime\Broker\AppMetrics; | |
| 11 | use Stewart\Runtime\Broker\AppPauseService; | |
| 12 | use Stewart\Runtime\Broker\AppTopology; | |
| 13 | use Stewart\Runtime\Broker\DaemonLaunchOptions; | |
| 14 | use Stewart\Runtime\Broker\Exposure\ExposureLink; | |
| 15 | use Stewart\Runtime\Broker\Exposure\ExposureReconciler; | |
| 16 | use Stewart\Runtime\Broker\GeneratedCodeDrift; | |
| 17 | use Stewart\Runtime\Broker\WorkerPool; | |
| 18 | use Stewart\Runtime\Broker\WorkerPoolListener; | |
| 19 | use Stewart\Runtime\Config\ConfigLoader; | |
| 20 | use Stewart\Runtime\Logging\LogVerbosityPolicy; | |
| 21 | ||
| 22 | final readonly class ReloadApplier | |
| 23 | { | |
| 24 | public function __construct( | |
| 25 | private AppTopology $topology, | |
| 26 | private AppPauseService $pauses, | |
| 27 | private AppMetrics $metrics, | |
| 28 | private ExposureLink $exposures, | |
| 29 | private ExposureReconciler $reconciler, | |
| 30 | private WorkerPool $pool, | |
| 31 | private WorkerPoolListener $workerEvents, | |
| 32 | private CatalogWarnings $catalogWarnings, | |
| 33 | private ConfigLoader $configs, | |
| 34 | private DaemonLaunchOptions $launch, | |
| 35 | private LogVerbosityPolicy $verbosity, | |
| 36 | private GeneratedCodeDrift $drift, | |
| 37 | private LoggerInterface $logger, | |
| 38 | ) {} | |
| 39 | ||
| 40 | public function applyReload(ReloadPlan $plan): void | |
| 41 | { | |
| 42 | $previous = $this->topology->getCatalog(); | |
| 43 | $this->topology->replaceTopology($plan->catalog, $plan->workerSlots); | |
| 44 | $this->pauses->followReloadedCatalog($previous); | |
| 45 | $this->metrics->replaceAppTotals($plan->workerSlots); | |
| 46 | $this->verbosity->replaceAppVerbosities($plan->catalog->enabled->listVerbositiesByAppId()); | |
| 47 | $this->drift->replaceGeneratedManifest($plan->generated); | |
| 48 | $this->drift->recheckGeneratedCode(); | |
| 49 | ||
| 50 | foreach ($previous->enabled->filter(static fn(AppDefinition $app): bool => $plan->catalog->enabled->find($app->id) === null) as $removed) { | |
| 51 | $this->exposures->forgetExposuresOfApp($removed->id); | |
| 52 | } | |
| 53 | ||
| 54 | $this->reconciler->restartAfterReload(); | |
| 55 | $this->catalogWarnings->logCatalogWarnings($plan->discovered, $plan->catalog, $this->configs->locateConfigFile($this->launch->configFile), $this->logger); | |
| 56 | $this->pool->applyWorkerSlots($plan->workerSlots, $this->workerEvents); | |
| 57 | } | |
| 58 | } |