feat(queue): add unique job deduplication support#197
Closed
romanstingler wants to merge 2 commits intostackkit:masterfrom
Closed
feat(queue): add unique job deduplication support#197romanstingler wants to merge 2 commits intostackkit:masterfrom
romanstingler wants to merge 2 commits intostackkit:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In
CloudTasksQueue.php, thetaskName()method unconditionally prepended aStr::ulid()to every task name, which bypassed Laravel'suniqueFor/uniqueId()mechanism. This caused duplicate tasks because Cloud Tasks saw each dispatch as a unique task name, even when the underlying job was the same.Changes made:
taskName()method (line 240-259): Now checks if the job is a unique job viaisUniqueJob(), meaning it has auniqueId()method and a truthyuniqueForproperty. If so,$job->uniqueId()is used as the task name without the ULID prefix. Non-unique jobs retain the original ULID-prefixed behavior.pushToCloudTasks()method (line 222-232): WrapsCloudTasksApi::createTask()in a try-catch forApiException. If the error is a 409 (ALREADY_EXISTS) and the job is unique, the exception is swallowed and the existing UUID is returned, matching Laravel's expected unique job behavior where dispatching a duplicate is a no-op.isUniqueJob()helper (line 262-268): Extracted the duck-typing check into a single private method to avoid duplication betweentaskName()andpushToCloudTasks().With this fix, a
HandleOrderjob withuniqueFor = 3600anduniqueId()returningHandle-Order-10-11479956619529will now create task names like:projects/.../tasks/Handle-Order-10-11479956619529Instead of the previous behavior:
projects/.../tasks/01KQWQQPH0902D52ERCJMEE872-Handle-Order-10-11479956619529Cloud Tasks will reject duplicates with
ALREADY_EXISTS, preventing multiple identical tasks from being queued.