veewee / composer-run-parallel
并行运行 composer 任务
1.3.0
2023-11-04 12:20 UTC
Requires
- php: ^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0
- composer-plugin-api: ~2.0
Requires (Dev)
- composer/composer: ^2.0
- react/promise: 1.2.1
- symfony/process: 2.8.52
README
这个 composer 插件允许您并行运行 composer 文件内的任务。不再需要等待特定任务!
安装
composer require --dev veewee/composer-run-parallel
或者全局安装 ...
composer require --global veewee/composer-run-parallel
示例
{ "scripts": { "php1": "@php -r 'sleep(3); echo \"1\";'", "php2": "@php -r 'echo \"2\";'" } }
以下命令将导致 php1 和 php2 同时并行执行
composer run parallel php1 php2
您甚至可以创建一个并行功能的快捷脚本,如下所示
{ "scripts": { "php1": "@php -r 'sleep(3); echo \"1\";'", "php2": "@php -r 'echo \"2\";'", "php1And2": "@parallel php1 php2" } }
composer run php1And2
如果任务失败怎么办?
{ "scripts": { "php1": "@php -r 'sleep(3); echo \"1\";'", "phpfail": "@php -r 'throw new Exception(\"FAIL\");'" } }
所有任务都将执行,如果其中一个失败,则并行任务也会失败
composer run parallel php1 phpfail
Succesfully ran:
php1
Failed running:
phpfail
Not all tasks could be executed succesfully!
注意:您也可以使用简写命令
composer parallel php1 phpfail
这很酷吧?如果我告诉你还有更多呢?
{ "scripts": { "wicked": [ "@parallel vendor php2", "@php1" ] } }
您甚至可以混合并行任务和串行任务,并可以同时嵌套多个并行任务。这样您就可以创建如下流程
- 首先进行一些检查
- 然后并行运行一些任务
- 如果一切顺利,最后完成一些阻塞的清理任务