Repository navigation
Document that concurrency key procs receive all job arguments - #840
Open
wintan1418 wants to merge 1 commit into
Open
wintan1418 wants to merge 1 commit into
wintan1418 wants to merge 1 commit into
Conversation
The key is computed with instance_exec(*arguments, &key), so a lambda that takes fewer parameters than the arguments the job is enqueued with raises ArgumentError when enqueuing. This is easy to miss when the job has optional or keyword arguments, as the lambda works until the job is enqueued with them.
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.
The concurrency
keyis computed withinstance_exec(*arguments, &key), so the proc gets every argument the job is enqueued with. A lambda checks how many arguments it gets, so a key like->(contact) { contact }works until the job is enqueued with one more argument, and thenperform_laterraises:The same happens with keyword arguments:
perform_later(contact, notify: false)passes the keywords as a second argument to the lambda. I ran into this in production with a job that is usually enqueued with one argument and sometimes with two. The error comes frominstance_execinconcurrency_controls.rband doesn't name the job or the key, so it took a while to find.The README says the proc "receives the job arguments as parameters", and the first example uses
->(arg1, arg2, *), but the examples below it are one-argument lambdas for one-argument jobs, so the*is easy to miss. This adds a note to thekeyoption saying that the proc gets all the arguments, including optional and keyword ones, and that a lambda needs to accept them, e.g.->(contact, *) { contact }. That's the same thing the test jobs do with->(job_result, **).