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

Fix RetryBatchCommand overlapping of failed jobs when run concurrently with the same Batch ID using isolatableId #4

Open
wants to merge 6 commits into
base: 10.x
Choose a base branch
from

Conversation

rybakihor
Copy link
Collaborator

@rybakihor rybakihor commented Jul 18, 2023

There is an issue in the job batching system that allows the same failed jobs to be added to the jobs table and executed multiple times (depending on the number of parallel processes of the RetryBatchCommand command for the same batch ID). This can result in a negative value for the number of pending jobs.

Steps to reproduce:

  • Create a batch with, for example, 1000 jobs.

  • Make the jobs fail (throw an exception)

  • Run the batch and verify that the value of failed_jobs in the pending_jobs table is 1000.

  • Make the jobs successful (remove the exception thrown)

  • Run several instances of the php artisan queue:retry-batch {id} command simultaneously or with a small time difference.

  • Check the job_batches table, and you will see that pending_jobs has a negative value. This indicates that some jobs have been executed multiple times by different processes.

Changes Made:

  • Updated the RetryBatchCommand class to implement the Isolatable interface.

  • Added the isolatableId method to the RetryBatchCommand class, which returns the value of the id argument as the custom mutex name.

By implementing the Isolatable interface and providing a custom mutex name using the isolatableId method, the RetryBatchCommand now benefits from isolated execution. This means that multiple instances of the RetryBatchCommand can be executed concurrently, as long as they have different id arguments. The custom mutex name ensures that only commands with the same id argument are mutually exclusive, allowing for more efficient and parallel processing of retry batches.

…he commandMutexName function in the CacheCommandMutex class
…ommand

- added getIsolatedMutexName function for get the custom mutex name for an isolated command
# Conflicts:
#	tests/Console/CacheCommandMutexTest.php
…ing-job-in-retry-batch-command-using-isolatable
@rybakihor rybakihor changed the title Fix RetryBatchCommand causes overlapping of failed jobs when run concurrently with the same Batch ID using Isolatable Fix RetryBatchCommand overlapping of failed jobs when run concurrently with the same Batch ID using isolatableId Aug 8, 2023
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

Successfully merging this pull request may close these issues.

1 participant