aguimaraes/circuit-breaker

Implementation of the circuit breaker pattern

Installs: 58 748

Dependents: 0

Suggesters: 0

Security: 0

Stars: 10

Watchers: 3

Forks: 2

Open Issues: 1

pkg:composer/aguimaraes/circuit-breaker

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

This package is auto-updated.

Last update: 2025-09-29 01:53:18 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
        
    }
}