rymanalu / laravel-circuit-breaker
Circuit Breaker pattern implementation in Laravel 5.
Installs: 1 191
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 5
Forks: 1
Open Issues: 0
Requires
- php: >=5.5.9
- illuminate/contracts: ^5.0
- illuminate/support: ^5.0
- nesbot/carbon: ^1.0
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.8
This package is auto-updated.
Last update: 2024-11-09 15:39:42 UTC
README
This package provides an implementation of Circuit Breaker pattern for Laravel 5.
Installation
First, install this package:
composer require rymanalu/laravel-circuit-breaker
Next, add the ServiceProvider to the providers array in config/app.php
:
Rymanalu\LaravelCircuitBreaker\CircuitBreakerServiceProvider::class,
You can use the facade for shorter code. Add this to your aliases:
'CircuitBreaker' => Rymanalu\LaravelCircuitBreaker\CircuitBreakerFacade::class,
APIs
<?php use CircuitBreaker; /** * Get the number of failures for the given key. * * @param string $key * @return int */ CircuitBreaker::failures($key); /** * Reset the number of failures for the given key. * * @param string $key * @return bool */ CircuitBreaker::resetFailures($key); /** * Increment the counter for a given key for a given decay time. * * @param string $key * @param float|int $decayMinutes * @return int */ CircuitBreaker::track($key, $decayMinutes = 1); /** * Determine if the given key has too many failures. * * @param string $key * @param int $maxFailures * @param int $decayMinutes * @return bool */ CircuitBreaker::tooManyFailures($key, $maxFailures, $decayMinutes = 1);