pransteter / etr-circuit-break-php
A little library to offer a simple manager of circuit breaker pattern.
dev-develop
2025-03-20 04:29 UTC
Requires
- php: >=8.2
Requires (Dev)
- phpro/grumphp: ^2.10
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11
- rregeer/phpunit-coverage-check: ^0.3.1
- squizlabs/php_codesniffer: *
This package is not auto-updated.
Last update: 2025-06-18 04:02:15 UTC
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); } }