Skip to content

Commit b10ca08

Browse files
authored
Merge pull request #173 from php-enqueue/fix-pheanstalk
fix pheanstalk redelivered, receive
2 parents 7b08854 + ff9ce81 commit b10ca08

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pkg/pheanstalk/PheanstalkConsumer.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,16 @@ public function getQueue()
4747
*/
4848
public function receive($timeout = 0)
4949
{
50-
if ($job = $this->pheanstalk->reserveFromTube($this->destination->getName(), $timeout / 1000)) {
51-
return $this->convertJobToMessage($job);
50+
if ($timeout === 0) {
51+
while (true) {
52+
if ($job = $this->pheanstalk->reserveFromTube($this->destination->getName(), 5)) {
53+
return $this->convertJobToMessage($job);
54+
}
55+
}
56+
} else {
57+
if ($job = $this->pheanstalk->reserveFromTube($this->destination->getName(), $timeout / 1000)) {
58+
return $this->convertJobToMessage($job);
59+
}
5260
}
5361
}
5462

@@ -101,7 +109,10 @@ public function reject(PsrMessage $message, $requeue = false)
101109
*/
102110
private function convertJobToMessage(Job $job)
103111
{
112+
$stats = $this->pheanstalk->statsJob($job);
113+
104114
$message = PheanstalkMessage::jsonUnserialize($job->getData());
115+
$message->setRedelivered($stats['reserves'] > 1);
105116
$message->setJob($job);
106117

107118
return $message;

0 commit comments

Comments
 (0)