I'm out of ideas, I'm using Spatie Media Library to upload and convert images. The package fires a job for each image in the form to do conversions and stuff. I want the user to have some kind of a feedback once all images has been uploaded successfully.
I thought of showing a loading icon and use Inertia manual visits to fire a get request every 10 seconds to a route that checks only the jobs related to this request and if completed I remove the loading icon. But how can I check only the queued jobs related to this request?
@MooseSaid omg, you are asking for checking if there are still jobs to be processed.. so as long as the size is bigger than 0, that means that there are still images that are being processed.. if the size is 0, the queue is empty and all the images have been processed. Makes sense?
@Nakov Makes perfect since but what if I have many jobs across my app? I don't want the user to wait for ALL jobs running across the app to be completed so that he get a feedback that his own has been completed. Or you think that's fine from you experience?
@MooseSaid yeah, that's a good point if you have lots of users and all of them uploaded images at the same time, then you will have your user wait until all jobs were processed.
Maybe similar to what @cosmeoes suggested, but that will work for single job, while you have multiple jobs per request. Pass to the job the total number of jobs and the current index, and then Queue::after event which each job dispatches compare if that's the last one and notify the user by dispatching another event. You won't need to make the 10 seconds visit this way. But also nothing guarantees that the job will be taken in the right order.
But this will process the images one after the other, not in the same time if you have multiple workers. So I don't know, chose what best works for you.
The way I've done this before is by adding something to the cache when you add the job to the queue and in the job deleting that cache when it finishes.