Skip to content

Commit 29a2d75

Browse files
author
Pantea Marius-ciclistu
committed
Backport laravel pull #54173 to issue #49389 and prevent issue from laravel/framework#57772 regarding WithoutOverlapping and ShouldBeUnique by setting a default of 7200 seconds for the locks instead of indefinite
1 parent f6b5c63 commit 29a2d75

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

illuminate/Bus/DatabaseBatchRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ public function transaction(Closure $callback)
323323
*/
324324
public function rollBack()
325325
{
326-
$this->connection->rollBack();
326+
$this->connection->rollBack(toLevel: 0);
327327
}
328328

329329
/**

illuminate/Bus/UniqueLock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function acquire($job): bool
3939
? $job->uniqueVia()
4040
: $this->cache;
4141

42-
return (bool)$cache->lock($this->getKey($job), $uniqueFor)->get();
42+
return (bool)$cache->lock($this->getKey($job), $uniqueFor <= 0 ? 7200 : $uniqueFor)->get();
4343
}
4444

4545
/**

illuminate/Queue/Jobs/Job.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ public function fail($e = null)
208208
}
209209
}
210210

211+
if (
212+
$e instanceof TimeoutExceededException &&
213+
('' !== $connection = (string)($config = $this->container['config'])['queue.failed.database']) &&
214+
\in_array($config['queue.failed.driver'], ['database', 'database-uuids'], true) &&
215+
$this->container->bound('db')
216+
) {
217+
$this->container->make('db')->connection($connection)->rollBack(toLevel: 0);
218+
}
219+
211220
try {
212221
// If the job has failed, we will delete it, call the "failed" method and then call
213222
// an event indicating the job has failed so it can be logged if needed. This is

illuminate/Queue/Middleware/WithoutOverlapping.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public function __construct($key = '', $releaseAfter = 0, $expiresAfter = 0)
5757
{
5858
$this->key = $key;
5959
$this->releaseAfter = $releaseAfter;
60-
$this->expiresAfter = $this->secondsUntil($expiresAfter);
60+
$expiresAfter = $this->secondsUntil($expiresAfter);
61+
$this->expiresAfter = $expiresAfter <= 0 ? 7200 : $expiresAfter;
6162
}
6263

6364
/**

0 commit comments

Comments
 (0)