Skip to content

Commit

Permalink
PDO based queues: Fix timeout not being a hard limit (as it is with R…
Browse files Browse the repository at this point in the history
…abbitMQ based queues)
  • Loading branch information
AllenJB committed Dec 18, 2020
1 parent e49c568 commit 2c0d109
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/Pdo/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,18 @@ public function consume(callable $callback, float $timeoutSecs): void
$callback($this, $message);
}

// Always process all the waiting responses
if (microtime(true) > $tsLimit) {
break;
}

// If more queue items are pending, loop immediately
if ($waitingReplies < 1) {
$waitingReplies = $this->getMessageCount();
}
if ($waitingReplies > 0) {
continue;
}

if (microtime(true) > $tsLimit) {
break;
}
usleep(10);
}
}
Expand Down Expand Up @@ -158,7 +159,7 @@ public function nack(QueueMessage $message): void
*/
public function getMessageCount(): ?int
{
$sql = "SELECT COUNT(queueid) AS `c`
$sql = "SELECT COUNT(queueid) AS `c`
FROM `q_{$this->name}`
WHERE `locked` = 0
AND (`dt_scheduled` IS NULL OR `dt_scheduled` < NOW())";
Expand All @@ -172,7 +173,7 @@ public function getMessageCount(): ?int
*/
public function getTotalMessageCount(): ?int
{
$sql = "SELECT COUNT(queueid) AS `c`
$sql = "SELECT COUNT(queueid) AS `c`
FROM `q_{$this->name}`
WHERE `locked` = 0";
$stmt = $this->pdo->query($sql);
Expand Down
9 changes: 5 additions & 4 deletions src/Pdo/ReplyQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,18 @@ public function consume(callable $callback, float $timeoutSecs): void
}
}

// Always process all the waiting responses
if (microtime(true) > $tsLimit) {
break;
}

// If more queue items are pending, loop immediately
if ($waitingReplies < 1) {
$waitingReplies = $this->getMessageCount();
}
if ($waitingReplies > 0) {
continue;
}

if (microtime(true) > $tsLimit) {
break;
}
usleep(10);
}
}
Expand Down

0 comments on commit 2c0d109

Please sign in to comment.