pransteter/etr-circuit-break-php
Composer 安装命令:
composer require pransteter/etr-circuit-break-php
包简介
A little library to offer a simple manager of circuit breaker pattern.
README 文档
README
Usage:
// Configure // - 1: Create a repository to persist and get the state: class MyAppCBStateRepository implements \Pransteter\MinimalCB\Contracts\StateRepository { public function saveState(string $index, \stdClass $state): bool { // code to save a state. } public function getState(string $index): ?\stdClass { // code to find a state. } } $repository = new MyAppCBStateRepository(); // - 2: Create a object of Configuration to set CB settings: $configuration = new \Pransteter\MinimalCB\DTOs\Configuration( processIdentifier: 'get-weather-data-from-api', failedTriesLimit: 5, secondsToStayOpened: 300, ); // Initialize MinimalCB: $cb = new MinimalCB( $configuration, $repository, )->begin(); // Check if can be executed if($cb->canExecute()) { // procede with execution and get the result. try { // - In case of success $cb->end(true); } catch (\Throwable $e) { // - executed with failure $cb->end(false); } }
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-11