borisguery/transient-error-handling

0.5 2022-09-15 10:15 UTC

This package is not auto-updated.

Last update: 2024-09-12 19:54:12 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

提供了一种在暂态错误/异常(如网络故障)上轻松重试操作的方法。

安装

通过Composer

$ composer require borisguery/transient-error-handling

使用方法

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. 

变更日志

请参阅变更日志了解最近更改的详细信息。

测试

$ composer test

致谢

许可协议

MIT许可协议(MIT)。有关更多信息,请参阅许可文件