Updated stamp creation to leverage the retry helper method #25
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.
Issue
When multiple requests happen (AJAX Async processing) and they will all have the same process hash the first request will work, some subset of following requests will fail, then the rest will work. This happens because if the hash doesn't already exist we block via a cache lock. This then returns a null instance for the subsequent requests until the record is created.
Solution
Updated the firstOrCreate method to use the retry helper. Now when a null instance would be returned instead we'll throw an exception and retry both finding the instances in the DB and checking on the Cache::lock.
I tried to set sane starting values (25ms sleep and 4 total retries) which should be well enough for most instances to create a single DB records (100ms total)
Release notes
Better handling of stamp creation to support high concurrency