Skip to content

Commit f331b5c

Browse files
[10.x] Dynamic maxTries for queued jobs (#49473)
* Added new method getJobTries to Queue.php to allow dynamic retry attempts on a job level * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent f510d4b commit f331b5c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Illuminate/Queue/Queue.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function createObjectPayload($job, $queue)
142142
'uuid' => (string) Str::uuid(),
143143
'displayName' => $this->getDisplayName($job),
144144
'job' => 'Illuminate\Queue\CallQueuedHandler@call',
145-
'maxTries' => $job->tries ?? null,
145+
'maxTries' => $this->getJobTries($job) ?? null,
146146
'maxExceptions' => $job->maxExceptions ?? null,
147147
'failOnTimeout' => $job->failOnTimeout ?? false,
148148
'backoff' => $this->getJobBackoff($job),
@@ -178,6 +178,27 @@ protected function getDisplayName($job)
178178
? $job->displayName() : get_class($job);
179179
}
180180

181+
/**
182+
* Get the maximum number of attempts for an object-based queue handler.
183+
*
184+
* @param mixed $job
185+
* @return mixed
186+
*/
187+
public function getJobTries($job)
188+
{
189+
if (! method_exists($job, 'tries') && ! isset($job->tries)) {
190+
return;
191+
}
192+
193+
if (isset($job->tries)) {
194+
return $job->tries;
195+
}
196+
197+
if (method_exists($job, 'tries') && ! is_null($job->tries())) {
198+
return $job->tries();
199+
}
200+
}
201+
181202
/**
182203
* Get the backoff for an object-based queue handler.
183204
*

0 commit comments

Comments
 (0)