-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from php-etl/fix/execute-actions-in-order
Respect loading order to execute actions & pipelines
- Loading branch information
Showing
3 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kiboko\Component\Runtime\Workflow; | ||
|
||
use Kiboko\Component\Runtime\Action\Console as ActionConsoleRuntime; | ||
use Kiboko\Component\State; | ||
use Kiboko\Contract\Action\ExecutingActionInterface; | ||
use Kiboko\Contract\Satellite\RunnableInterface; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
|
||
class ActionProxy implements RunnableInterface | ||
{ | ||
/** @var list<callable> */ | ||
private array $queuedCalls = []; | ||
|
||
public function __construct( | ||
callable $factory, | ||
private readonly ConsoleOutput $output, | ||
private readonly ExecutingActionInterface $action, | ||
private readonly State\StateOutput\Workflow $state, | ||
private readonly string $filename, | ||
) { | ||
$this->queuedCalls[] = static function (ActionConsoleRuntime $runtime) use ($factory): void { | ||
$factory($runtime); | ||
}; | ||
} | ||
|
||
public function run(int $interval = 1000): int | ||
{ | ||
$runtime = new ActionConsoleRuntime($this->output, $this->action, $this->state->withAction($this->filename)); | ||
|
||
foreach ($this->queuedCalls as $queuedCall) { | ||
$queuedCall($runtime); | ||
} | ||
|
||
$this->queuedCalls = []; | ||
|
||
return $runtime->run($interval); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters