(Update) Only delete upsert data after successful upsertion #3943
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.
TODO: need to ensure the next upsert isn't started before the previous upsert finishes. (Does laravel's scheduler allow only one at a time when it's more frequently than a minute?)The laravel scheduler repeats the job as many times as needed waiting 5 seconds in between each time. Once the minute finishes, it doesn't run anymore: https://github.com/laravel/framework/blob/966a22ac8f7a5191e17818ce5eb5d0df2543e114/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php#L228.
It needed
->withoutOverlapping(2)
to ensure the next upsert is skipped if previous upsert is still running. I chose a 2 minute cache lock ttl which provides an extra minute after the run of the previous minute has finished to wait for any deadlocks to finish erroring (max of 5 times is specified in the transaction).