Skip to content

Commit

Permalink
PDO based queues: Fix excessively low poll interval, and make it conf…
Browse files Browse the repository at this point in the history
…igurable
  • Loading branch information
AllenJB committed Oct 20, 2021
1 parent 96d6ba3 commit a524cdc
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Pdo/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function publish(QueueMessage $message, \DateTimeImmutable $delayTo = nul
}


public function consume(callable $callback, float $timeoutSecs): void
public function consume(callable $callback, float $timeoutSecs, float $pollIntervalSecs = 0.5): void
{
$tsLimit = microtime(true) + $timeoutSecs;
$waitingReplies = 0;
Expand Down Expand Up @@ -125,7 +125,7 @@ public function consume(callable $callback, float $timeoutSecs): void
continue;
}

usleep(10);
usleep($pollIntervalSecs * 1000000);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Pdo/RPCQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function publish(QueueMessage $message): PromiseInterface
}


public function consume(callable $callback, float $timeoutSecs): void
public function consume(callable $callback, float $timeoutSecs, float $pollIntervalSecs = 0.1): void
{
$this->replyQueue->consume($callback, $timeoutSecs);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Pdo/ReplyQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function getName(): string
}


public function consume(callable $callback, float $timeoutSecs): void
public function consume(callable $callback, float $timeoutSecs, float $pollIntervalSecs = 0.1): void
{
$tsLimit = microtime(true) + $timeoutSecs;
$waitingReplies = 0;
Expand Down Expand Up @@ -169,7 +169,7 @@ public function consume(callable $callback, float $timeoutSecs): void
continue;
}

usleep(10);
usleep($pollIntervalSecs * 1000000);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/QueueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function publish(QueueMessage $message, \DateTimeImmutable $delayTo = nul
/**
* @param callable $callback Callback with parameters: QueueInterface $this, QueueMessage
*/
public function consume(callable $callback, float $timeoutSecs): void;
public function consume(callable $callback, float $timeoutSecs, float $pollIntervalSecs): void;


public function ack(QueueMessage $message): void;
Expand Down
2 changes: 1 addition & 1 deletion src/RPCQueueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function publish(QueueMessage $message): PromiseInterface;
/**
* @param callable $callback Callback with parameters: RPCQueueInterface $this, QueueMessage
*/
public function consume(callable $callback, float $timeoutSecs): void;
public function consume(callable $callback, float $timeoutSecs, float $pollIntervalSecs): void;


public function setExpectedResponseCount(?int $count): void;
Expand Down
2 changes: 1 addition & 1 deletion src/Rabbit/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function publish(QueueMessage $message, \DateTimeImmutable $delayTo = nul
}


public function consume(callable $callback, float $timeoutSecs): void
public function consume(callable $callback, float $timeoutSecs, float $pollIntervalSecs = 0.1): void
{
throw new UnsupportedOperationException("Consumption is not supported by RabbitQueue");
}
Expand Down

0 comments on commit a524cdc

Please sign in to comment.