Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pending job count not correct on batch with failures allowed #1063

Closed
bilfeldt opened this issue Aug 25, 2021 · 4 comments
Closed

Pending job count not correct on batch with failures allowed #1063

bilfeldt opened this issue Aug 25, 2021 · 4 comments

Comments

@bilfeldt
Copy link
Contributor

bilfeldt commented Aug 25, 2021

  • Horizon Version: 5.7.11
  • Laravel Version: 8.56.0
  • PHP Version: 7.4
  • Redis Driver & Version: predis/phpredis: Unknown
  • Database Driver & Version: MySQL 8.0

Description:

When using batches with failures allowed then the Batch information about pending jobs shown in Horizon is misleading.

Example (can be found in github repo below):

\Illuminate\Support\Facades\Bus::batch([
        new \App\Jobs\TestJob(1), // Will succeed on first attempt
        new \App\Jobs\TestJob(2), // Will succeed on second attempt
        new \App\Jobs\TestJob(3), // Will succeed on third attempt
        new \App\Jobs\TestJob(4), // Will succeed on fourth attempt (which will never happen since $maxExceptions = 3)
        new \App\Jobs\TestJob(0), // Will never succeed
    ])->allowFailures()->dispatch();

This batch should have a total of 5 jobs and 3 of them should eventually succeed (60%). Now the end result in Horizon shows 2 pending jobs + 2 failed jobs:

Screenshot 2021-08-25 at 14 58 05

I think this is a bug since only jobs not marked as "failed" or "completed" should appear as pending (since they will be processed soon). This is also confirmed by no pending jobs appearing:

Screenshot 2021-08-25 at 14 58 08

While there are in fact three completed jobs:

Screenshot 2021-08-25 at 14 58 11

and two failed:

Screenshot 2021-08-25 at 14 58 13

Steps To Reproduce:

A Github repository showcasing the error can be seen here: https://github.com/bilfeldt/bug-report

  1. Start Horizon (remember to use redis as queue driver): php artisan horizon
  2. Go to /batch which will dispatch the batch of jobs
  3. Go to the horizon dashboard and see the images also attached above
@themsaid
Copy link
Member

This is the expected behaviour. Pending jobs are one that haven't finished. In your case, these are the failed jobs.

@driesvints
Copy link
Member

I tried to improve the UI here: #1064

@bilfeldt
Copy link
Contributor Author

bilfeldt commented Aug 26, 2021

Thanks for the feedback @themsaid. It makes sense that those failed jobs are in fact also pending jobs since they have not completed. That said I would expect that they are somewhere stored as being processed since they are not going to be handled by any worker from now on? Cannot seem to find this information from the batch itself though.

I like your #1064 contribution @driesvints, much appreciated.

@themsaid, @driesvints is there a way we could indicate that all jobs has been handled and no further processing will occur? It can be tricky to know when exactly the batch has no further jobs that will be processed - especially if you also use the "Retry Failed Jobs" feature, as the "Pending" jobs will consist of both jobs being retried and jobs that will no longer be retried. Maybe we should not remove the "Pending" badge as soon as there are "Failures" but instead show both badges?

I have sketched the process below, which indicates that it can be tricky to know the meaning of "pending" jobs and determining if the batch has completed running (simply added a sleep(5) to the job from the original issue above).

Process using retry

No jobs yet processed - 5 pending jobs that will be processed

Screenshot 2021-08-26 at 23 09 48

First job processed (success) - 4 pending jobs that will be processed

Screenshot 2021-08-26 at 23 09 51

Second job processed (success) - 3 pending jobs that will be processed

Screenshot 2021-08-26 at 23 27 07

Third job processed (success) - 2 pending jobs that will be processed

Screenshot 2021-08-26 at 23 10 03

Fourth job processed (failed) - 2 pending jobs but only one that will be processed

Screenshot 2021-08-26 at 23 10 06

Fifth job processed (failed) - 2 pending jobs but none that will be processed

Screenshot 2021-08-26 at 23 10 40

Retry jobs

Now clicking the "Retry Failed Jobs" button.

Fourth job retried (failed) - 2 pending jobs but one that will be processed

Screenshot 2021-08-26 at 23 14 50

Fifth job retried (failed) - 2 pending jobs but none that will be processed

Screenshot 2021-08-26 at 23 14 55

@driesvints
Copy link
Member

Hey @bilfeldt, I think that all looks good to be honest. It's probably best that if you want to improve something here that you attempt a PR.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants