[11.x] Fix integrity constraint violation on failed_jobs_uuid_unique #53264
+139
−48
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 #53230
Listeners are bound each time
Artisan::call('queue:work')
is called, and ifDatabaseUuidFailedJobProvider
is used, then when a failed job occurs it tries to add it to the database multiple times resulting in an integrity constraint violation on the unique key.Rather than using the global events system, this PR uses SplObserver / SplSubject (Observer Design pattern) which allows the observer to be overwritten every time
Artisan::call('queue:work')
is called.Are you receptive to this? If so I can look at adding a test. If not, please suggest an alternative way about going about fixing the issue. It's unclear to me whether
logFailedJob()
could just be moved into the worker, but that might result in failed jobs being logged outside of thequeue:work
command.