Skip to content

Commit

Permalink
5.6 - database queue wrap transactions, code cleaning
Browse files Browse the repository at this point in the history
- pop() transaction wrapped in closure for easier readability, removing side effect of marshalJob() which nonintuitively commits the transaction
  • Loading branch information
ph4r05 committed Dec 14, 2017
1 parent 24c4482 commit c38ee67
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/Illuminate/Queue/DatabaseQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Illuminate\Queue;

use Throwable;
use Illuminate\Support\Carbon;
use Illuminate\Database\Connection;
use Illuminate\Queue\Jobs\DatabaseJob;
Expand Down Expand Up @@ -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;
});
}

/**
Expand Down Expand Up @@ -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
);
Expand Down

0 comments on commit c38ee67

Please sign in to comment.