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

Failed job not showing #530

Closed
shadoWalker89 opened this issue Feb 28, 2019 · 9 comments · Fixed by #532
Closed

Failed job not showing #530

shadoWalker89 opened this issue Feb 28, 2019 · 9 comments · Fixed by #532
Labels

Comments

@shadoWalker89
Copy link

shadoWalker89 commented Feb 28, 2019

Hi,

So i have a failed job that is not showing on the horizon failed jobs tab. But it is showing in the dashboard

image

But the list of failed jobs is empty

image

Even though the ajax request shows the total as 1 but the jobs array is empty

image

And this is also a screenshot of the database

image

If i go to the recent jobs tab i see the failed job

image

And when i click on it it opens the failed job details page at this uri ".../failed/11"

image

I'm using

php 7.2.15
laravel 5.7.28
horizon 3.0.0

@driesvints
Copy link
Member

Hmm. I've been looking into this but can't seem to reproduce it. Can you perhaps post some code and/or set up a test app?

@shadoWalker89
Copy link
Author

shadoWalker89 commented Feb 28, 2019

I'm not doing anything fancy.

Just using the ShouldQueue interface on a mail class.

The error that you are seeing is caused by me making a syntax error in the email markdown file to test the failed jobs tab.

I'm not familiar with horizon code, and this is my first time using horizon but i suspect that this has something to do with redis and this is why.

The redis command being executed to get the failed jobs is zrange failed_jobs 1 50
The redis command being executed to get the failed jobs count is zcount failed_jobs -inf -1550754504

In my redis-cli if i do zrangebyscore horizon:failed_jobs 1 50 i get (empty list or set)
If i do zrangebyscore horizon:failed_jobs -inf 50 i get (empty list or set) i get

1) "11"

I think the problem is when trying to get the failed jobs but with 1 instead of -inf

If you follow this call

? $this->paginate($request)

down to
$type, $afterIndex + 1, $afterIndex + 50

You will see that in the ajax request the query string starting_at=0, to the $afterIndex + 1 will give 1 that is reflected in the redis command to get failed jobs ids zrange failed_jobs 1 50

@driesvints
Copy link
Member

Can you try to replace line 160 with the following and see what happens?

$type, $afterIndex ? $afterIndex + 1 : '-inf', $afterIndex + 50

@shadoWalker89
Copy link
Author

That will give an error Redis::zRange() expects parameter 2 to be integer, string given
But replacing the -inf with -1 does the trick and the failed job is displayed.

But if you check this line

$afterIndex = $afterIndex === null ? -1 : $afterIndex;

You will see that similar check is there with the exception that is checking for === null

I think that maybe the line below is the one that should change

return $this->jobs->getFailed($request->query('starting_at', -1))->map(function ($job) {

if the starting_at is 0 then pass null

Also should change the default value to null if the parameter starting_at does not exist.
Because back to the line 160 if -1 is passed the will have -1 + 1 which gives 0 and then the command will be

zrange failed_jobs 0 50

Which does not work and return an empty set

I think maybe this is the proper change (it works for me)

// Failed jobs controller
    protected function paginate(Request $request)
    {
        $starting_at = $request->query('starting_at', null);

        return $this->jobs->getFailed($starting_at === '0' ? null : $starting_at)->map(function ($job) {
            return $this->decode($job);
        });
    }

Note: I don't know but maybe you should also the paginateByTag() method on the controller

@driesvints
Copy link
Member

Can you try this?

return $this->jobs->getFailed($request->query('starting_at') ?: -1)->map(function ($job) {
    return $this->decode($job);
});

@shadoWalker89
Copy link
Author

Yeah that works as well

@driesvints
Copy link
Member

Cool. I think the paginateByTag method is ok because the implementation is slightly different there. Actually I believe that's the solution all along. Can you try one more time with this change:

return $this->jobs->getFailed($request->query('starting_at', -1) + 1)->map(function ($job) {
    return $this->decode($job);
});

@shadoWalker89
Copy link
Author

Not this last one does not work.
Go back to having an empty array for the jobs

@driesvints
Copy link
Member

Ah I see, that's because it's a different method call. I'll send in a PR with the fix. Thanks for reporting.

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

Successfully merging a pull request may close this issue.

2 participants