Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dave97's avatar

Queue::size($queueName) always return 0

Hi,

I am using a Redis Queue in my project deployed on Digital Ocean with Forge. I have more than 100jobs on a queue linked to 10 workers and i need to know when this batch of job is completed.

Based on : https://laracasts.com/discuss/channels/laravel/send-notification-after-all-instances-of-a-job-completes I first tried to use Queue event: 'Queue::after(function (JobProcessed $event) {...' to increment a counter in my db every time a job is completed but the solution fails as it seems not all completed jobs increase the counter (maybe some collision when accessing the counter row in db....)

So i implemented a subscriber to check the queue size but i always get Queue::size($queueName) == 0, even when the jobs are processing. And i cant find too much documentation on the use of such method.

public function subscribe(Dispatcher $events) {
    $events->listen(Looping::class, self::class . '@onQueueLoop'); // >= Laravel 5.4
}

public function onQueueLoop() {
    $queueName = 'exchanges';
    $queueSize = \Queue::size($queueName);

    if ($queueSize == 0) {
        // Trigger your event.
        $commandLog = CommandLog::where('command',     InfoProcess::$name_command)->where('status', 'all_jobs_initiated')->latest()->first();
        if (!empty($commandLog)) {
            echo " onQueueLoop Completed";
            $commandLog->status = "Completed ".$queueSize;
            $commandLog->save();
         
        }else{
            //TODO log the fact that no commandLog
        }
    }
}

Am i missing something on how to check the Queue size of a specific Redis Queue?

0 likes
0 replies

Please or to participate in this conversation.