Skip to content

Commit e35c494

Browse files
authored
Merge pull request #8 from php-etl/fix/execute-actions-in-order
Respect loading order to execute actions & pipelines
2 parents 78ce3dd + 575a6d3 commit e35c494

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

src/ActionProxy.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kiboko\Component\Runtime\Workflow;
6+
7+
use Kiboko\Component\Runtime\Action\Console as ActionConsoleRuntime;
8+
use Kiboko\Component\State;
9+
use Kiboko\Contract\Action\ExecutingActionInterface;
10+
use Kiboko\Contract\Satellite\RunnableInterface;
11+
use Symfony\Component\Console\Output\ConsoleOutput;
12+
13+
class ActionProxy implements RunnableInterface
14+
{
15+
/** @var list<callable> */
16+
private array $queuedCalls = [];
17+
18+
public function __construct(
19+
callable $factory,
20+
private readonly ConsoleOutput $output,
21+
private readonly ExecutingActionInterface $action,
22+
private readonly State\StateOutput\Workflow $state,
23+
private readonly string $filename,
24+
) {
25+
$this->queuedCalls[] = static function (ActionConsoleRuntime $runtime) use ($factory): void {
26+
$factory($runtime);
27+
};
28+
}
29+
30+
public function run(int $interval = 1000): int
31+
{
32+
$runtime = new ActionConsoleRuntime($this->output, $this->action, $this->state->withAction($this->filename));
33+
34+
foreach ($this->queuedCalls as $queuedCall) {
35+
$queuedCall($runtime);
36+
}
37+
38+
$this->queuedCalls = [];
39+
40+
return $runtime->run($interval);
41+
}
42+
}

src/Console.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
use Kiboko\Component\Action\Action;
88
use Kiboko\Component\Pipeline\Pipeline;
9-
use Kiboko\Component\Runtime\Action\ActionRuntimeInterface;
10-
use Kiboko\Component\Runtime\Action\Console as ActionConsoleRuntime;
119
use Kiboko\Component\Runtime\Pipeline\PipelineRuntimeInterface;
1210
use Kiboko\Component\State;
1311
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
12+
use Kiboko\Contract\Satellite\RunnableInterface;
1413
use Kiboko\Contract\Satellite\RunnableInterface as JobRunnableInterface;
1514
use Symfony\Component\Console\Output\ConsoleOutput;
1615

@@ -37,13 +36,13 @@ public function loadPipeline(string $filename): PipelineRuntimeInterface
3736
return new PipelineProxy($factory, $this->output, $pipeline, $this->state, basename($filename));
3837
}
3938

40-
public function loadAction(string $filename): ActionRuntimeInterface
39+
public function loadAction(string $filename): RunnableInterface
4140
{
4241
$factory = require $filename;
4342

4443
$action = new Action();
4544

46-
return $factory(new ActionConsoleRuntime($this->output, $action, $this->state->withAction(basename($filename))));
45+
return new ActionProxy($factory, $this->output, $action, $this->state, basename($filename));
4746
}
4847

4948
public function job(JobRunnableInterface $job): self

src/WorkflowRuntimeInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77
use Kiboko\Contract\Pipeline\SchedulingInterface;
88
use Kiboko\Contract\Satellite\RunnableInterface;
99

10-
interface WorkflowRuntimeInterface extends SchedulingInterface, RunnableInterface
11-
{
12-
}
10+
interface WorkflowRuntimeInterface extends SchedulingInterface, RunnableInterface {}

0 commit comments

Comments
 (0)