Skip to content

Commit

Permalink
feat: add method to check if there're pre fetched tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
shpran committed Aug 30, 2023
1 parent d86a5f8 commit ddd01f2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions models/classes/taskQueue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ public function getNumberOfTasksToReceive()
return $this->getBroker()->getNumberOfTasksToReceive();
}

/**
* @inheritdoc
*/
public function hasPreFetchedMessages(): bool
{
return $this->getBroker()->hasPreFetchedMessages();
}

/**
* @param TaskInterface $task
*
Expand Down
10 changes: 9 additions & 1 deletion models/classes/taskQueue/Queue/Broker/AbstractQueueBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,22 @@ public function pop()
return $this->popPreFetchedMessage();
}

/**
* @inheritdoc
*/
public function hasPreFetchedMessages(): bool
{
return $this->preFetchedQueue->count();
}

/**
* Pop a task from the internal queue.
*
* @return TaskInterface|null
*/
private function popPreFetchedMessage()
{
if ($this->preFetchedQueue->count()) {
if ($this->hasPreFetchedMessages()) {
return $this->preFetchedQueue->dequeue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@ public function delete(TaskInterface $task);
* @return int
*/
public function getNumberOfTasksToReceive();

/**
* Check if the internal queue contains any tasks.
*/
public function hasPreFetchedMessages(): bool;
}
5 changes: 5 additions & 0 deletions models/classes/taskQueue/QueueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public function isSync();
*/
public function getNumberOfTasksToReceive();

/**
* Check if the internal queue contains any tasks.
*/
public function hasPreFetchedMessages(): bool;

/**
* Set new broker.
*
Expand Down

0 comments on commit ddd01f2

Please sign in to comment.