From 4bf79be49ae5a8a0b4dbef2a7d4e821d2f6d8aa2 Mon Sep 17 00:00:00 2001 From: Dusan Klinec Date: Thu, 14 Dec 2017 08:45:58 +0100 Subject: [PATCH] 5.6 - database queue wrap transactions, code cleaning - pop() transaction wrapped in closure for easier readability, removing side effect of marshalJob() which nonintuitively commits the transaction --- src/Illuminate/Queue/DatabaseQueue.php | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Illuminate/Queue/DatabaseQueue.php b/src/Illuminate/Queue/DatabaseQueue.php index 65cb50251104..75a0161e81c8 100644 --- a/src/Illuminate/Queue/DatabaseQueue.php +++ b/src/Illuminate/Queue/DatabaseQueue.php @@ -2,7 +2,6 @@ namespace Illuminate\Queue; -use Throwable; use Illuminate\Support\Carbon; use Illuminate\Database\Connection; use Illuminate\Queue\Jobs\DatabaseJob; @@ -191,19 +190,13 @@ public function pop($queue = null) { $queue = $this->getQueue($queue); - try { - $this->database->beginTransaction(); - + return $this->database->transaction(function () use ($queue) { if ($job = $this->getNextAvailableJob($queue)) { return $this->marshalJob($queue, $job); } - - $this->database->commit(); - } catch (Throwable $e) { - $this->database->rollBack(); - - throw $e; - } + + return null; + }); } /** @@ -267,8 +260,6 @@ protected function marshalJob($queue, $job) { $job = $this->markJobAsReserved($job); - $this->database->commit(); - return new DatabaseJob( $this->container, $this, $job, $this->connectionName, $queue );