Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check the status of a queue in Laravel?

I need to submit a number of jobs to a Laravel queue to process some uploaded CSV files. These jobs could be finished in one second if the files are small, or a few seconds if they're bigger, or possibly up to a minute if the CSV files are very big. And I can't tell in advance how big the files will be.

When the user goes to the "results" page, I need to display the results - but only if the queue has finished the jobs. If the queue is still processing, I need to display a "try again later" message.

So - is there a way to check, from a controller, whether the queue has finished?

I'm currently using Laravel 5.1 but would happily upgrade if that helps. And I'm currently using the database queue driver. Ideally I'd love to find a general technique that works for all queue drivers, but if the only way to do it is to check a database table then I guess that's what I have to do.

Thanks!

like image 256
Brendan White Avatar asked Aug 07 '16 12:08

Brendan White


People also ask

How do I know if my Laravel queue is working?

$this->mailer->queue($view, $data, function ($message) use ($toEmail, $toName, $subject) { $message ->to($toEmail, $toName) ->subject($subject); }); This will successfully run, but if the queue is not 'listening', the job gets pushed on to the job table, forever. I am looking for something like \Queue::isListening();

What is Laravel queue sync?

Sync, or synchronous, is the default queue driver which runs a queued job within your existing process. With this driver enabled, you effectively have no queue as the queued job runs immediately.

What is the difference between job and queue in Laravel?

Jobs and QueuesThe line itself is the Queue, and each customer in the line is a Job. In order to process Jobs in the Queue you need command line processes or daemons. Think of launching a queue daemon on the command line as adding a new bank teller to the pool of available bank tellers.


1 Answers

I know this is a year old, but why not create a new queue per upload with a unique key based on that request.

$job = (new ProcessCSVJob($data))->onQueue($uniqueQueueName);

You can then simply either do a count in the database on the queue name field if you want a DB only solution.

To work across all queue types you can use the Queue size method to return the queue size.

$queue = App::make('queue.connection');
$size = $queue->size($uniqueQueueName);

This is in Laravel 5.4. Not sure how backwards compatible this is.

like image 168
Robert Norman Avatar answered Oct 08 '22 06:10

Robert Norman