codenamephp / deploymentchecks.async
一个允许您并行运行部署检查的包。
1.0.0
2024-01-20 23:46 UTC
Requires
- php: ^8.2
- codenamephp/deploymentchecks.base: *
- spatie/async: ^1.5
Requires (Dev)
- mockery/mockery: ^1.5
This package is auto-updated.
Last update: 2024-09-21 01:39:52 UTC
README
一个允许您并行运行部署检查的包。
安装
最简单的方式是通过 composer。只需在您的命令行中运行 composer require codenamephp/deploymentchecks.async
,它将为您安装最新版本。
您还应明确安装 codenamephp/deploymentchecks.base 包,因为在几乎所有情况下您都将直接使用它。
重要说明
因为 spatie/async(提供底层异步功能的包)通过序列化和反序列化在进程/线程之间传递数据,所以想与此兼容的包必须确保检查是可序列化的。这意味着检查不得包含任何资源、闭包或其他不可序列化数据。
使用方法
就像使用任何其他部署检查集合一样使用它。唯一的不同之处在于,您需要提供一个池和一些工厂。线程的数量也可以通过池进行配置。
use de\codenamephp\deploymentchecks\async\Check\Factory\FromCheck\WithErrorHandlerFactory; use de\codenamephp\deploymentchecks\async\Collection\AsyncCheckCollection; use de\codenamephp\deploymentchecks\base\Check\Result\Collection\ResultCollection; use de\codenamephp\deploymentchecks\base\Check\Result\WithExitCodeInterface; use de\codenamephp\deploymentchecks\base\ExitCode\DefaultExitCodes; use de\codenamephp\deploymentchecks\http\RunTestsOnHttpResponse; use de\codenamephp\deploymentchecks\http\Test\StatusCode; use GuzzleHttp\Psr7\Request; require_once __DIR__ . '/../vendor/autoload.php'; $result = (new AsyncCheckCollection( // This is the collection that will run the checks instead of the default sequential collection new \Spatie\Async\Pool(), // This is the pool that will run the checks in parallel new ResultCollection(), // This is the result collection that will be filled with the results of the checks new WithErrorHandlerFactory(), // This is the factory that will create the checks from the checks that are passed to the collection new RunTestsOnHttpResponse( // These are the checks that will be run, in this case from the codenamephp/deploymentchecks.http package new Request('GET', 'https://'), 'Frontpage should be available', new StatusCode(200), ), new RunTestsOnHttpResponse( new Request('GET', 'https:///admin'), 'Admin login page should be available', new StatusCode(401), ) ))->run(); exit($result instanceof WithExitCodeInterface ? $result->exitCode() : ($result->successful() ? DefaultExitCodes::SUCCESSFUL->value : DefaultExitCodes::ERROR->value));