Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

lemonde/php-circuit-breaker-bundle

Repository files navigation

php-circuit-breaker-bundle

Build Status Build Status Scrutinizer Code Quality Code Coverage

Description

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

How to install ?

Requirements

  • =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

How to use ?

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));

How to contribute ?

You can add issue, and create pull request. https://github.com/lemonde/php-circuit-breaker-bundle/blob/master/.github/CONTRIBUTING.md