I'm using Laravel Horizon to manage my queued jobs. They take up to 15 minutes. That's why I want to show the use an estimated wait time. Something like. "Your job starts in 6 minutes..."
Laravel Horizon already calculates the estimated wait time of a whole queue. I can access it via the WorkloadRepository. Now I need to know the position in the queue of a single job to calculate the wait time for this specific one. Has anybody an idea how to do that? I'm a bit clueless and not too familiar with the depth of Laravel Horizon.
As far as I know, you can only ask to retrieve the number of jobs that are in the queue from Redis. It's hard to determine the time because each job is different.
Also, the wait time is hard to calculate. The job might process all records really fast or a bit slower depending on how much calculation power is available on the server.
Do you trigger this job via the scheduler? If so you can calculate it based on that.
Yes, every job is different and the wait time Horizon calculates depends on the duration of the predecessors. I'm not expecting a really accurate wait time. But IMO better an inaccurate time than showing just "Your job starts soon..." and the user has to wait 10 minutes.
No, I'm not trigger the job via the task scheduler.
My simple idea was just to take the wait time of a whole queue from Horizon (because they have already made the work of calculating it depending on the number of processes etc.), divide it by the number of queued jobs with the status pending and multiply it with the position of the job I want to calculate the wait time for.
My problem is to figure out the position in a queue. Is there a simple way to do that?
The only thing I can think of using querying directory to Redis and just fetching all the jobs and convert it to an array and do some calculations on that.