generated from Sammyjo20/package-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Hi! Love the idea and syntax of the package, got into one problem tho. For a big batch import job instead of limiting the rates, as I understand it, it just queues up hundreds of jobs each second.
Command example:
while (true) {
try {
$price = $api->prices()->get();
$this->info($price);
} catch(\Exception $e) {
dump($e->getMessage());
}
} The execution:
- Prints price x times
- Rate limit is hit
- Delay next request of remaining 5 seconds limit
- Delay another 100 request
- Delay next request of remaining 4 seconds limit
- Delay another 100 request
- ...
- 5 seconds later, send 100 requests
- 6 seconds later, another batch of 100 requests
And I get tons of 429.
You see the issue? I feel like it would be nice if this time calculation could take everything else queued into account too:
| $existingDelay = $pendingRequest->delay()->get() ?? 0; |
Sadly I have know clue of how to do that and if it would be possible, so I'm not much of any more help here.
In the mean time it looks like this will be my very basic rate limiter:
public function send(Request $request, MockClient $mockClient = null): Response
{
// π ... πͺ ... π«
try {
return $this->createPendingRequest($request, $mockClient)->send();
} catch(\Exception $e) {
if(str($e->getMessage())->contains('429')) {
// This is our request limiter, let's wait a bit and retry
sleep(3);
return $this->createPendingRequest($request, $mockClient)->send();
}
throw $e;
}
}Metadata
Metadata
Assignees
Labels
No labels