[3.0] Fix false jobs causing front-end not to display them #582
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #304
I’ve ran into issues while running Horizon in production where some of the failed jobs that are collected from Redis have
false
as all the values on the job (includingname
,id
,connection
etc.). I’m not exactly sure how these occur (possibly from orphan processes?) Screenshot:This creates problem for Horizon’s front-end (gets stuck in loading state). This is because the front-end determines the job’s base name using JavaScript’s string.includes(). Unfortunately, when the id is a boolean this method falls
t.includes is not a function
horizon/base.js at 3.0 · laravel/horizon · GitHub
Fix
In the
RedisJobRepository
getJobs
method there is already a check to make sure that the job is an array and the the id of the job isn't null. This PR adds a check to make sure that the id of the job isn'tfalse
and filter those out.Relevant line:
https://github.com/laravel/horizon/blob/3.0/src/Repositories/RedisJobRepository.php#L196
I chose to explicitly check if the id is false as opposed to using PHP's
empty()
as empty("0") will return true and would filter a job id that is equal to 0.