-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFactory.php
29 lines (24 loc) · 1.13 KB
/
Factory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
namespace Ejsmont\CircuitBreakerBundle;
use Ejsmont\CircuitBreaker\Core\CircuitBreaker;
use Ejsmont\CircuitBreaker\Storage\Decorator\ArrayDecorator;
use Ejsmont\CircuitBreakerBundle\Storage\DoctrineCacheAdapter;
use Doctrine\Common\Cache\Cache;
/**
* Class allows easy assembly of circuit breaker instances using Doctrine cache objects.
*/
class Factory extends \Ejsmont\CircuitBreaker\Factory {
/**
* Creates a circuit breaker instance using doctrine cache adapter.
*
* @param Cache $doctrineCache instance of a doctrine cache backend to use
* @param int $maxFailures how many times do we allow service to fail before considering it offline
* @param int $retryTimeout how many seconds should we wait before attempting retry
*
* @return CircuitBreakerInterface
*/
public static function getDoctrineCacheInstance(Cache $doctrineCache, $maxFailures = 20, $retryTimeout = 30) {
$storage = new ArrayDecorator(new DoctrineCacheAdapter($doctrineCache));
return new CircuitBreaker($storage, $maxFailures, $retryTimeout);
}
}