<?php
final class Deployment
{
/**
* @param array<string, list<string>> $pipelineStages
*/
public function run(array $pipelineStages): void
{
$pipeline = new Fiber(function (array $pipelineStages): string {
Fiber::suspend('Pipeline initialized.');
foreach ($pipelineStages as $stage => $steps) {
foreach ($steps as $step) {
Fiber::suspend("Stage '{$stage}': step '{$step}' completed.");
}
}
return 'Deployment successful.';
});
$monitor = new Fiber(function (): string {
Fiber::suspend('Monitoring system initialized.');
while (true) {
Fiber::suspend('System health: OK.');
}
});
$pipeline->start($pipelineStages);
$monitor->start();
while (! $pipeline->isTerminated()) {
printf("[Pipeline] %s\n", $pipeline->resume());
printf("[Monitor] %s\n", $monitor->resume());
}
$result = $pipeline->getReturn();
printf("[Result] %s\n", $result);
}
}
$stages = [
'build' => ['compile', 'lint', 'optimize'],
'test' => ['unit', 'integration', 'e2e'],
'package' => ['zip', 'sign'],
'deploy' => ['upload', 'release', 'notify'],
];
(new Deployment())->run($stages);
preferences:
25.4 ms | 404 KiB | 5 Q