Everything is MIT licensed and unsupported unless otherwise stated. Use at your own risk.
Implement circuit breaker pattern see here http://martinfowler.com/bliki/CircuitBreaker.html.
You can find explanation in french here https://medium.com/eleven-labs/le-circuit-breaker-k%C3%A9sako-4763e13a4a03
-
=PHP 7
- use LoggerInterface
- use CacheInterface
composer require lemonde/php-circuit-breaker-bundle:lastest
Add in your AppKernel.php
public function registerBundles()
{
$bundles = [
....
new CircuitBreakerBundle\CircuitBreakerBundle(),
];
return $bundles;
}
Add in your config.yml
circuit_breaker:
# Number fail possible in circuit breaker
threshold: 5
# Time in seconds resend call after circuit breaker is open
timeout: 20
And add config to CacheInterface in your config.yml
framework:
cache:
app: cache.adapter.filesystem
Before your service's call
if ($this->get('circuit.breaker')->isOpen('your-service')) {
// If service is down
}
You need to send status on service to each call
// $status is bool
$this->get('dispatcher')->dispatch('circuit.breaker', new CircuitBreakerEvent('your-service', $status));
You can add issue, and create pull request. https://github.com/lemonde/php-circuit-breaker-bundle/blob/master/.github/CONTRIBUTING.md