Skip to content

aguimaraes/circuit-breaker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

circuit-breaker

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
        
    }
}