public function DatabaseQueue::numberOfItems in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Queue/DatabaseQueue.php \Drupal\Core\Queue\DatabaseQueue::numberOfItems()
- 10 core/lib/Drupal/Core/Queue/DatabaseQueue.php \Drupal\Core\Queue\DatabaseQueue::numberOfItems()
Retrieves the number of items in the queue.
This is intended to provide a "best guess" count of the number of items in the queue. Depending on the implementation and the setup, the accuracy of the results of this function may vary.
e.g. On a busy system with a large number of consumers and items, the result might only be valid for a fraction of a second and not provide an accurate representation.
Return value
int An integer estimate of the number of items in the queue.
Overrides QueueInterface::numberOfItems
File
- core/
lib/ Drupal/ Core/ Queue/ DatabaseQueue.php, line 101
Class
- DatabaseQueue
- Default queue implementation.
Namespace
Drupal\Core\QueueCode
public function numberOfItems() {
try {
return (int) $this->connection
->query('SELECT COUNT([item_id]) FROM {' . static::TABLE_NAME . '} WHERE [name] = :name', [
':name' => $this->name,
])
->fetchField();
} catch (\Exception $e) {
$this
->catchException($e);
// If there is no table there cannot be any items.
return 0;
}
}