[8.x] Add takeUntilTimeout
method to the lazy collection
#34444
Merged
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.
This PR adds a
takeUntilTimeout
to theLazyCollection
class, which lets you stop a long running process after a given timeout:This is especially useful for Laravel Vapor apps, since AWS will kill any long-running processes (after 15 minutes). See here for an example.
Imagine you have a huge list of invoices in your DB, which need to be submitted one by one:
This will submit as many invoices as there is time for, and then dispatch the job again to keep going.
If you can submit invoices in bulk, you can even chunk them before the
takeUntilTimeout
call:P.S. This would've been ssoooo much easier to test with
Carbon
, especially with the new time travel stuff. But it makes no sense to addCarbon
as a dependency toilluminate/collections
just for this.I really hate all that stupid Mockery code I had to write, but I see no other way. Gives you a new level of appreciation for proper time travel 😄