diff --git a/src/Interfaces/GraphInterface.php b/src/Interfaces/GraphInterface.php index 8cc7046..0150c54 100644 --- a/src/Interfaces/GraphInterface.php +++ b/src/Interfaces/GraphInterface.php @@ -18,24 +18,40 @@ use Chevere\DataStructure\Interfaces\VectorInterface; /** - * Describes the component in charge of defining jobs dependencies order. + * Describes the component in charge of defining job execution order, where each node contains async jobs. * * @extends MappedInterface> */ interface GraphInterface extends MappedInterface, ToArrayInterface { + /** + * Determines if the graph has the given `$job`. + */ public function has(string $job): bool; /** + * Retrieve dependencies for the given `$job`. + * * @return VectorInterface */ public function get(string $job): VectorInterface; + /** + * Determines if the given `$job` has the given `$dependencies`. + */ public function hasDependencies(string $job, string ...$dependencies): bool; + /** + * Return an instance with the specified `$name` and `$job` put. + * + * This method MUST retain the state of the current instance, and return + * an instance that contains the specified `$name` and `$job` put. + */ public function withPut(string $name, JobInterface $job): self; /** + * Returns the graph as an array of arrays, where each array is a node with async jobs. + * * @return array> */ public function toArray(): array; diff --git a/src/Interfaces/JobsInterface.php b/src/Interfaces/JobsInterface.php index 125a2be..b41e5d7 100644 --- a/src/Interfaces/JobsInterface.php +++ b/src/Interfaces/JobsInterface.php @@ -25,8 +25,6 @@ */ interface JobsInterface extends MappedInterface { - public function __construct(JobInterface ...$jobs); - public function has(string $job): bool; public function get(string $job): JobInterface; @@ -46,10 +44,7 @@ public function references(): MapInterface; */ public function keys(): array; - /** - * @return array - */ - public function graph(): array; + public function graph(): GraphInterface; public function withAdded(JobInterface ...$jobs): self; diff --git a/src/Jobs.php b/src/Jobs.php index 0dc788f..103d2c8 100644 --- a/src/Jobs.php +++ b/src/Jobs.php @@ -74,9 +74,9 @@ public function __construct(JobInterface ...$jobs) $this->putAdded(...$jobs); } - public function graph(): array + public function graph(): GraphInterface { - return $this->graph->toArray(); + return $this->graph; } public function variables(): MapInterface diff --git a/src/Runner.php b/src/Runner.php index e5b054e..60caf17 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -48,7 +48,7 @@ public function withRun(): RunnerInterface { $new = clone $this; $jobs = $new->run->workflow()->jobs(); - foreach ($jobs->graph() as $node) { + foreach ($jobs->graph()->toArray() as $node) { $promises = $new->getPromises($node); /** @var RunnerInterface[] $responses */ $responses = wait(all($promises)); diff --git a/tests/JobsTest.php b/tests/JobsTest.php index 0aaf80b..07b533b 100644 --- a/tests/JobsTest.php +++ b/tests/JobsTest.php @@ -82,7 +82,7 @@ public function testAsync(): void [ ['j1', 'j2'], ], - $jobs->graph() + $jobs->graph()->toArray() ); } @@ -97,7 +97,7 @@ public function testSync(): void ['j1'], ['j2'], ], - $jobs->graph() + $jobs->graph()->toArray() ); } @@ -112,7 +112,7 @@ public function testWithDependsOnJob(): void ['j1'], ['j2'], ], - $jobs->graph() + $jobs->graph()->toArray() ); } @@ -140,7 +140,7 @@ public function testWithDependsOnPreviousMultiple(): void ['j1', 'j2'], ['j3'], ], - $jobs->graph() + $jobs->graph()->toArray() ); } @@ -159,7 +159,7 @@ public function testWithDependsOnPreviousSingle(): void ['j2'], ['j3'], ], - $jobs->graph() + $jobs->graph()->toArray() ); } @@ -182,7 +182,7 @@ public function testWithDependsMix(): void ['j3', 'j5'], ['j6'], ], - $jobs->graph() + $jobs->graph()->toArray() ); } @@ -331,7 +331,7 @@ public function testWithRunIfReference(): void ['j1'], ['j2', 'j3'], ], - $jobs->graph() + $jobs->graph()->toArray() ); $this->assertTrue( $jobs->references()->has($true->__toString(), $false->__toString())