88
99class ThrottlesExceptions
1010{
11+ /**
12+ * The developer specified key that the rate limiter should use.
13+ *
14+ * @var string
15+ */
16+ protected $ key ;
17+
1118 /**
1219 * The maximum number of attempts allowed before rate limiting applies.
1320 *
@@ -27,14 +34,7 @@ class ThrottlesExceptions
2734 *
2835 * @var int
2936 */
30- protected $ retryAfterMinutes ;
31-
32- /**
33- * The rate limiter key.
34- *
35- * @var string
36- */
37- protected $ key ;
37+ protected $ retryAfterMinutes = 0 ;
3838
3939 /**
4040 * The callback that determines if rate limiting should apply.
@@ -48,7 +48,7 @@ class ThrottlesExceptions
4848 *
4949 * @var string
5050 */
51- protected $ prefix = 'circuit_breaker : ' ;
51+ protected $ prefix = 'laravel_throttles_exceptions : ' ;
5252
5353 /**
5454 * The rate limiter instance.
@@ -62,15 +62,13 @@ class ThrottlesExceptions
6262 *
6363 * @param int $maxAttempts
6464 * @param int $decayMinutes
65- * @param int $retryAfterMinutes
6665 * @param string $key
66+ * @return void
6767 */
68- public function __construct ($ maxAttempts = 10 , $ decayMinutes = 10 , $ retryAfterMinutes = 0 , string $ key = '' )
68+ public function __construct ($ maxAttempts = 10 , $ decayMinutes = 10 )
6969 {
7070 $ this ->maxAttempts = $ maxAttempts ;
7171 $ this ->decayMinutes = $ decayMinutes ;
72- $ this ->retryAfterMinutes = $ retryAfterMinutes ;
73- $ this ->key = $ key ;
7472 }
7573
7674 /**
@@ -129,6 +127,19 @@ public function withPrefix(string $prefix)
129127 return $ this ;
130128 }
131129
130+ /**
131+ * Specify the number of seconds a job should be delayed when it is released (before it has reached its max exceptions).
132+ *
133+ * @param int $backoff
134+ * @return $this
135+ */
136+ public function backoff ($ backoff )
137+ {
138+ $ this ->retryAfterMinutes = $ backoff ;
139+
140+ return $ this ;
141+ }
142+
132143 /**
133144 * Get the cache key associated for the rate limiter.
134145 *
@@ -137,7 +148,20 @@ public function withPrefix(string $prefix)
137148 */
138149 protected function getKey ($ job )
139150 {
140- return $ this ->prefix .md5 (empty ($ this ->key ) ? get_class ($ job ) : $ this ->key );
151+ return $ this ->key ? $ this ->prefix .$ this ->key : $ this ->prefix .$ job ->job ->uuid ();
152+ }
153+
154+ /**
155+ * Set the value that the rate limiter should be keyed by.
156+ *
157+ * @param string $key
158+ * @return $this
159+ */
160+ public function by ($ key )
161+ {
162+ $ this ->key = $ key ;
163+
164+ return $ this ;
141165 }
142166
143167 /**
0 commit comments