Skip to content

Commit

Permalink
fix mi wea
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Apr 9, 2022
1 parent 855db74 commit 8031f0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 36 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chevere/workflow",
"description": "A chevere workflow component.",
"description": "The chevere workflow component",
"homepage": "https://chevere.org",
"type": "library",
"license": "Apache-2.0",
Expand All @@ -13,7 +13,7 @@
],
"require": {
"amphp/parallel": "^1.4",
"chevere/chevere": "^0.6.x-dev",
"chevere/chevere": "^0.7",
"psr/container": "^2.0"
},
"require-dev": {
Expand Down
41 changes: 16 additions & 25 deletions src/WorkflowRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Chevere\Message\Message;
use Chevere\Response\Interfaces\ResponseInterface;
use Chevere\Throwable\Exceptions\InvalidArgumentException;
use Chevere\Throwable\Exceptions\RuntimeException;
use function Chevere\VarSupport\deepCopy;
use Chevere\Workflow\Interfaces\JobInterface;
use Chevere\Workflow\Interfaces\WorkflowRunInterface;
Expand Down Expand Up @@ -54,7 +53,12 @@ public function withRun(): WorkflowRunnerInterface
$job,
);
}
$responses = wait(all($promises));

try {
$responses = wait(all($promises));
} catch (Throwable $e) {
vdd($e->getOriginalMessage());
}
$new = end($responses);
}

Expand All @@ -63,36 +67,23 @@ public function withRun(): WorkflowRunnerInterface

public function runJob(string $name): void
{
try {
$job = $this->workflowRun()->workflow()->jobs()->get($name);
$actionName = $job->action();
/** @var ActionInterface $action */
$action = new $actionName();
$action = $action->withContainer($this->container);
$arguments = $this->getJobArguments($job);
$response = $this->getActionResponse($action, $arguments);
deepCopy($response);
$this->addJob($name, $response);
}
// @codeCoverageIgnoreStart
catch (Throwable $e) {
throw new RuntimeException(
previous: $e,
message: (new Message('Caught %throwable% at job:%job% when running action:%action%'))
->code('%throwable%', $e::class)
->code('%job%', $name)
->code('%action%', $actionName)
);
}
// @codeCoverageIgnoreEnd
$job = $this->workflowRun()->workflow()->jobs()->get($name);
$actionName = $job->action();
/** @var ActionInterface $action */
$action = new $actionName();
$action = $action->withContainer($this->container);
$arguments = $this->getJobArguments($job);
$response = $this->getActionResponse($action, $arguments);
deepCopy($response);
$this->addJob($name, $response);
}

private function getActionResponse(
ActionInterface $action,
array $arguments
): ResponseInterface {
try {
return $action->runner(...$arguments);
return $action->getResponse(...$arguments);
}
// @codeCoverageIgnoreStart
catch (Throwable $e) {
Expand Down
12 changes: 3 additions & 9 deletions tests/WorkflowRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,16 @@ public function testWorkflowRunner(): void
$this->assertEquals($workflowRunFunction->workflow(), $workflowRunner->workflowRun()->workflow());
$action1 = new WorkflowRunnerTestJob1();
$this->assertSame(
$action1->run(
...$action1->getArguments(...[
'foo' => $foo,
])->toArray()
),
$action1->run(foo: $foo),
$workflowRun->get('step1')->data()
);
$foo = $workflowRun->get('step1')->data()['response1'];
$action2 = new WorkflowRunnerTestJob2();
$this->assertSame(
$action2
->run(
...$action2->getArguments(...[
'foo' => $foo,
'bar' => $bar,
])->toArray()
foo: $foo,
bar: $bar,
),
$workflowRun->get('step2')->data()
);
Expand Down

0 comments on commit 8031f0a

Please sign in to comment.