Skip to content

Commit 9533eed

Browse files
committed
fix sqs consume timeout
1 parent 7b6a9cb commit 9533eed

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎pkg/sqs/SqsConsumer.php‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,21 @@ public function getQueue()
9898
*/
9999
public function receive($timeout = 0)
100100
{
101-
$timeout /= 1000;
101+
$maxLongPollingTime = 20; // 20 is max allowed long polling value
102+
103+
if ($timeout === 0) {
104+
while (true) {
105+
if ($message = $this->receiveMessage($maxLongPollingTime)) {
106+
return $message;
107+
}
108+
}
109+
}
110+
111+
$timeout = (int) ceil($timeout / 1000);
112+
113+
if ($timeout > $maxLongPollingTime) {
114+
throw new \LogicException(sprintf('Max allowed SQS receive message timeout is: "%s"', $maxLongPollingTime));
115+
}
102116

103117
return $this->receiveMessage($timeout);
104118
}

0 commit comments

Comments
 (0)