Concurrency and Throttle cannot both be used on a job#9
Open
jeremywadsack wants to merge 1 commit intonickelser:masterfrom
Open
Concurrency and Throttle cannot both be used on a job#9jeremywadsack wants to merge 1 commit intonickelser:masterfrom
jeremywadsack wants to merge 1 commit intonickelser:masterfrom
Conversation
…hrottle strategies
Author
|
@nickelser Any chance you could review this? We're using the gem and our fork of it but would love to get a released version that covers this. (I see there are some other PRs that would be useful, like Redis namespace support). Thanks! |
|
It'd be great if someone can review this! |
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.
While the use case for this is likely slim (only one job can be run at a time and no more than 2 in a second or something), there's a possibility that you would want to have both
concurrencyandthrottleon the same job. This would fail with non-prockeys because the::lock_keymethod is memoizing the return value when called by the first strategy to acquire a lock, and the second strategy would get the same key.This resolves that by removing the memoization. That was part of the original design, but in that case each individual strategy memoized it's own lock (e.g.
@concurrency_key). In 6fe8aad with refactoring for Rails 5 this changed to a commonBase::lock_keymethod and the memoization became shared.I don't think that the memoization adds much. The calls that are memoized are a hash lookup, string interpolation, and
gsub, none of which are that complex. Additionally,::lock_keylooks like it's only called once per job, so memoization probably has no effect.This PR includes a test to verify that the keys are different. That seemed a simpler test (and more determinate) that trying to contrive a situation to prove that both locks are working. It also more clearly documents the thing being asserted. Let me know if this works or if you would like more coverage.