Skip to content

Commit

Permalink
5.5 database queue - transactions wrapped in closures, tsx management…
Browse files Browse the repository at this point in the history
… fixed

- fixes #7046
  • Loading branch information
ph4r05 committed Dec 12, 2017
1 parent 242d438 commit 02fe24a
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/Illuminate/Queue/DatabaseQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,24 @@ protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts
*
* @param string $queue
* @return \Illuminate\Contracts\Queue\Job|null
* @throws \Exception|\Throwable
*/
public function pop($queue = null)
{
$queue = $this->getQueue($queue);

$this->database->beginTransaction();
try {
$this->database->beginTransaction();

if ($job = $this->getNextAvailableJob($queue)) {
return $this->marshalJob($queue, $job);
}
if ($job = $this->getNextAvailableJob($queue)) {
return $this->marshalJob($queue, $job);
}

$this->database->commit();
$this->database->commit();
} catch (\Throwable $ex) {
$this->database->rollBack();
throw $ex;
}
}

/**
Expand Down Expand Up @@ -288,16 +294,15 @@ protected function markJobAsReserved($job)
* @param string $queue
* @param string $id
* @return void
* @throws \Exception|\Throwable
*/
public function deleteReserved($queue, $id)
{
$this->database->beginTransaction();

if ($this->database->table($this->table)->lockForUpdate()->find($id)) {
$this->database->table($this->table)->where('id', $id)->delete();
}

$this->database->commit();
$this->database->transaction(function () use ($queue, $id) {
if ($this->database->table($this->table)->lockForUpdate()->find($id)) {
$this->database->table($this->table)->where('id', $id)->delete();
}
});
}

/**
Expand Down

0 comments on commit 02fe24a

Please sign in to comment.