aguimaraes/circuit-breaker

Implementation of the circuit breaker pattern

v2.0.0 2019-10-15 09:51 UTC

This package is auto-updated.

Last update: 2024-10-30 02:04:56 UTC


README

CircleCI codecov

Usage example

$cb = new Aguimaraes\CircuitBreaker(
    new Aguimaraes\Adapter\ACPu()
);

// number of errors necessary to open the circuit
$cb->setThreshold('my-service', 10); 

// wait x seconds to check if service is back
$cb->setTimeout('my-service', 60);

$response = null;

if ($cb->isAvailable('my-service')) {
    try {
        
        $response = $service->makeCall();
        $cb->reportSuccess('my-service');
        
    } catch (ServiceException $e) {
        
        $cb->reportFailure('my-service');
        
    } catch (NonServiceRelatedException $e) {
        
        // something went wrong and it was not the service fault
        
    }
}