8000 5.5 database queue - transactions wrapped in closures, tsx management… · ph4r05/framework@02fe24a · GitHub
[go: up one dir, main page]

Skip to content

Commit 02fe24a

Browse files
committed
5.5 database queue - transactions wrapped in closures, tsx management fixed
- fixes laravel#7046
1 parent 242d438 commit 02fe24a

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/Illuminate/Queue/DatabaseQueue.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,24 @@ protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts
184184
*
185185
* @param string $queue
186186
* @return \Illuminate\Contracts\Queue\Job|null
187+
* @throws \Exception|\Throwable
187188
*/
188189
public function pop($queue = null)
189190
{
190191
$queue = $this->getQueue($queue);
191192

192-
$this->database->beginTransaction();
193+
try {
194+
$this->database->beginTransaction();
193195

194-
if ($job = $this->getNextAvailableJob($queue)) {
195-
return $this->marshalJob($queue, $job);
196-
}
196+
if ($job = $this->getNextAvailableJob($queue)) {
197+
return $this->marshalJob($queue, $job);
198+
}
197199

198-
$this->database->commit();
200+
$this->database->commit();
201+
} catch (\Throwable $ex) {
202+
$this->database->rollBack();
203+
throw $ex;
204+
}
199205
}
200206

201207
/**
@@ -288,16 +294,15 @@ protected function markJobAsReserved($job)
288294
* @param string $queue
289295
* @param string $id
290296
* @return void
297+
* @throws \Exception|\Throwable
291298
*/
292299
public function deleteReserved($queue, $id)
293300
{
294-
$this->database->beginTransaction();
295-
296-
if ($this->database->table($this->table)->lockForUpdate()->find($id)) {
297-
$this->database->table($this->table)->where('id', $id)->delete();
298-
}
299-
300-
$this->database->commit();
301+
$this->database->transaction(function () use ($queue, $id) {
302+
if ($this->database->table($this->table)->lockForUpdate()->find($id)) {
303+
$this->database->table($this->table)->where('id', $id)->delete();
304+
}
305+
});
301306
}
302307

303308
/**

0 commit comments

Comments
 (0)
0