graph TD;
A --> B
A --> C
A --> D
D --> G
C --> G
C --> F
B --> F
B --> E
B --> H
H --> I
E --> I
F --> I
G --> I
假设我们有一系列任务,拓扑结构如上图所示,顶点代表任务,边缘代表依赖关系。(A完成后才能完成B、C、D,B完成后才能完成H、E、F...最后完成I)
declare(strict_types=1);
namespace SwowCloud\Job\Dag\Task;
use SwowCloud\Job\Contract\DagInterface;
use SwowCloud\Job\Kernel\Concurrent\ConcurrentMySQLPattern;
class Task1 implements DagInterface
{
public function __construct(string $startDate, string $endDate)
{
$this->startDate = $startDate;
$this->endDate = $endDate;
}
/**
* @param array $results 返回之前执行任务的结果集
* {@inheritDoc}
*/
public function run(array $results): int | bool
{
echo "Task1::run()\n";
return true;
}
public function isNext(): bool
{
return true;
}
public function getIdentity(): int | string
{
return 1;
}
public function getTimeout(): int
{
return 5;
}
public function runConcurrentMySQLPattern(ConcurrentMySQLPattern $pattern): mixed
{
}
}
{
"class": "Serendipity\\Job\\Dag\\Task\\Task1",
"params": {
"startDate": "2021-06-09",
"endDate": "2021-06-19"
}
}
throw new DagException('never done!');
php bin/job dag:start --host=127.0.0.1 --port=9764