aguimaraes/circuit-breaker

Implementation of the circuit breaker pattern

Maintainers

Package info

github.com/aguimaraes/circuit-breaker

pkg:composer/aguimaraes/circuit-breaker

Statistics

Installs: 59 827

Dependents: 0

Suggesters: 0

Stars: 10

Open Issues: 0

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

This package is auto-updated.

Last update: 2026-02-25 22:09:44 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
        
    }
}