Skip to content

Commit b8a70e9

Browse files
committed
adjust behavior
1 parent 2584678 commit b8a70e9

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/Illuminate/Queue/Middleware/ThrottlesExceptions.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ class ThrottlesExceptions
1515
*/
1616
protected $key;
1717

18+
/**
19+
* Indicates whether the throttle key should use the job's UUID.
20+
*
21+
* @var bool
22+
*/
23+
protected $byJob = false;
24+
1825
/**
1926
* The maximum number of attempts allowed before rate limiting applies.
2027
*
@@ -148,7 +155,13 @@ public function backoff($backoff)
148155
*/
149156
protected function getKey($job)
150157
{
151-
return $this->key ? $this->prefix.$this->key : $this->prefix.$job->job->uuid();
158+
if ($this->key) {
159+
return $this->prefix.$this->key;
160+
} elseif ($this->byJob) {
161+
return $this->prefix.$job->job->uuid();
162+
}
163+
164+
return $this->prefix.md5(get_class($job));
152165
}
153166

154167
/**
@@ -164,6 +177,18 @@ public function by($key)
164177
return $this;
165178
}
166179

180+
/**
181+
* Indicate that the throttle key should use the job's UUID.
182+
*
183+
* @return $this
184+
*/
185+
public function byJob()
186+
{
187+
$this->byJob = true;
188+
189+
return $this;
190+
}
191+
167192
/**
168193
* Get the number of seconds that should elapse before the job is retried.
169194
*

0 commit comments

Comments
 (0)