borisguery / transient-error-handling
Transient Error Handling
Installs: 97 818
Dependents: 2
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.3||^8.0
- beberlei/assert: ^3.2
Requires (Dev)
- phpunit/phpunit: ^9.3
This package is not auto-updated.
Last update: 2024-11-21 20:40:41 UTC
README
Provide a way to easily retry actions on transient errors / exceptions such as a network failure.
Install
Via Composer
$ composer require borisguery/transient-error-handling
Usage
use Bgy\TransientFaultHandling\RetryStrategies\FixedInterval; use Bgy\TransientFaultHandling\RetryPolicy; use Bgy\TransientFaultHandling\ErrorDetectionStrategies\TransientErrorCatchAllStrategy; $retryCount = 10; $retryIntervalInMicroseconds = 1000000 // 1 sec $retryStrategy = new FixedInterval($retryCount, $retryIntervalInMicroseconds); $errorDetectionStrategy = new TransientErrorCatchAllStrategy(); // You may want to implement your own $retryPolicy = new RetryPolicy($errorDetectionStrategy, $retryStrategy); $retryPolicy->execute(function() { // try to connect to MySQL throw new ConnectionError("Unable to connect to MySQL"); }); // This configuration will try to execute 10 times the function everyseconds if an exception is thrown.
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Credits
License
The MIT License (MIT). Please see License File for more information.