rymanalu / laravel-circuit-breaker
Laravel 5 中的电路断路器模式实现。
v1.0.1
2016-12-08 09:13 UTC
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-09-09 15:21:17 UTC
README
此包为 Laravel 5 提供了电路断路器模式的实现。
安装
首先,安装此包
composer require rymanalu/laravel-circuit-breaker
接下来,将 ServiceProvider 添加到 config/app.php
文件中的 providers 数组
Rymanalu\LaravelCircuitBreaker\CircuitBreakerServiceProvider::class,
您可以使用 facade 来缩短代码。将以下内容添加到您的别名中
'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);