Lines
100.00%
14 / 14
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ReloadPlanner | 100.00% | 14 / 14 | 100.00% | 2 / 2 | 3 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| planReload | 100.00% | 13 / 13 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Broker\Reload; | |
| 6 | ||
| 7 | use Stewart\Contracts\Exception\StewartException; | |
| 8 | use Stewart\Runtime\App\AppCatalogResolver; | |
| 9 | use Stewart\Runtime\Broker\AppPlacement; | |
| 10 | use Stewart\Runtime\Broker\DaemonLaunchOptions; | |
| 11 | use Stewart\Runtime\Config\ConfigLoader; | |
| 12 | use Stewart\Runtime\Config\StewartConfig; | |
| 13 | use Stewart\Runtime\Exception\BrokerError; | |
| 14 | use Stewart\Runtime\Exception\BrokerException; | |
| 15 | ||
| 16 | final readonly class ReloadPlanner | |
| 17 | { | |
| 18 | public function __construct( | |
| 19 | private ConfigLoader $configs, | |
| 20 | private AppCatalogResolver $catalogs, | |
| 21 | private AppPlacement $placement, | |
| 22 | private ConfigChangeClassifier $changes, | |
| 23 | private DaemonLaunchOptions $launch, | |
| 24 | private StewartConfig $runningConfig, | |
| 25 | ) {} | |
| 26 | ||
| 27 | /** @throws StewartException */ | |
| 28 | public function planReload(ReloadCheckReport $report): ReloadPlan | |
| 29 | { | |
| 30 | $configFile = $this->launch->configFile; | |
| 31 | ||
| 32 | // The child checked one version of the file; applying another would skip the check. | |
| 33 | if ($this->configs->fingerprintConfigFile($configFile) !== $report->configFingerprint) { | |
| 34 | throw BrokerException::createForReason(BrokerError::ReloadConfigChanged, path: $this->configs->locateConfigFile($configFile)); | |
| 35 | } | |
| 36 | ||
| 37 | $config = $this->configs->loadConfig($configFile, $this->launch->listConfigOverrides()); | |
| 38 | $discovered = $report->restoreDiscovery(); | |
| 39 | $catalog = $this->catalogs->resolveCatalog($discovered, $config->apps, $config->workers, $this->launch->selection); | |
| 40 | ||
| 41 | return new ReloadPlan( | |
| 42 | $discovered, | |
| 43 | $catalog, | |
| 44 | $this->placement->planWorkerSlots($catalog->enabled, $config), | |
| 45 | $this->changes->listSettingsNeedingRestart($this->runningConfig, $config), | |
| 46 | $report->generated, | |
| 47 | ); | |
| 48 | } | |
| 49 | } |