Laravel-excel: [QUESTION] How can i detect when all jobs, using chunk and queue, are finished ?

Created on 28 Aug 2017  路  8Comments  路  Source: Maatwebsite/Laravel-Excel

Package version, Laravel version

"maatwebsite/excel": "~2.1.0",
"laravel/framework": "5.4.*"

Expected behaviour

When i use the chunk method with queue, to import data from csv, how can i detect when all jobs are processed ? I mean, i need to notify the users, when the import process are terminated. So, i know that i can use queue::after() from Laravel to catch the JobProcessed event, but could be usefull to have , with maatwebsite/excel package one last jobs in the end in order to know when all jobs are finished ?

Or there is antoher simplest way to do that ?

Actual behaviour

I don't know if right now the package offer the opportunity to catch when all jobs are processed.

All 8 comments

@mdeprezzo Did you find the answer to your question? Please share it

@Silwady Simply, i've added an extra job at the end of the chunk code. So redis put this job at the end of the others chunks. It isnt't maybe, so excat, because if some job fail, and redis try again to execute, i don't know still works.

If you use the database queue, to the queue to take a name, you can query after the queue :: after according to the queue name queue is empty, to determine whether the execution is complete

One of my problems, I pressed 100 size of chunk into the queue and found the queue execution time is too slow.

Adding an extra job at the end of the chunk code is the best solution to notify me if the queue is done. But I cannot determine if any chunk has a problem while reading the data.

@Silwady if we put a check inside every job to detect when all jobs are complete, based on some condition, could be better than adding in the end an extra jobs ? Or maybe are there some other queue services, that include some auto check, compared to redis ?

You could use Queue::readyNow('queue-name') to see how many remaining jobs there are.

-Edit:
Just noticed that the readyNow method is only available if you use the RedisQueue with Laravel Horizon. Laravel Horizon adds that functionality to the RedisQueue.

@mdeprezzo can you share your extra job code? i cant figure out how to get the end of the chunk

Since this popped up on google search when I was looking for this solution, I'm sharing

In version 3.1, this issue is solved by appending jobs. Docs link: https://laravel-excel.maatwebsite.nl/3.1/imports/queued.html#appending-jobs

Was this page helpful?
0 / 5 - 0 ratings