public function Database::countJobs in Advanced Queue 8
Gets an estimated number of jobs in the queue.
The accuracy of this number might vary. On a busy system with a large number of consumers and jobs, the result might only be valid for a fraction of a second and not provide an accurate representation.
Return value
array The estimated number of jobs, grouped per job status. Only the estimate for the 'queued' status is guaranteed to be present, other estimates (processing/success/failed) depend on backend capabilities and configuration.
Overrides BackendInterface::countJobs
File
- src/
Plugin/ AdvancedQueue/ Backend/ Database.php, line 95
Class
- Database
- Provides the database queue backend.
Namespace
Drupal\advancedqueue\Plugin\AdvancedQueue\BackendCode
public function countJobs() {
// Ensure each state gets a count, even if it's 0.
$jobs = [
Job::STATE_QUEUED => 0,
Job::STATE_PROCESSING => 0,
Job::STATE_SUCCESS => 0,
Job::STATE_FAILURE => 0,
];
$query = 'SELECT state, COUNT(job_id) FROM {advancedqueue} WHERE queue_id = :queue_id GROUP BY state';
$counts = $this->connection
->query($query, [
':queue_id' => $this->queueId,
])
->fetchAllKeyed();
foreach ($counts as $state => $count) {
$jobs[$state] = $count;
}
return $jobs;
}