JustSteveKing / laravel-envoyer-sdk

A simple to use PHP class to work with the Laravel Envoyer API
MIT License
36 stars 15 forks source link

Rate limiting by Envoyer is triggered, but not handled properly #10

Open mike503 opened 2 years ago

mike503 commented 2 years ago

This quick loop to get a list of all collaborators on all projects winds up hitting some sort of rate limit (silently)

I have 78 projects, so this would be a total of 79 API calls. Seems like when it hits project #60 (so it's done 60 API calls back to back, I believe) it starts coming back empty. It doesn't seem to throw an exception that I can trap. I can't imagine Envoyer itself is responding with a 200 and empty result, instead of a 524 / some non-200 response.

To reproduce, have over 60 projects and run this:

$i = 1;
$collabs = array();
foreach ($envoyer->projects->all()->projects as $project) {
  echo "{$i}. {$project->name}\n";
  $j = 1;
  foreach ($envoyer->collaborators->on($project->id)->all()->collaborators as $collab) {
    echo "  {$j}. got a collab {$collab->email}\n";
    $j++;
  }
  $i++;
  // sleep(3) here does space it out enough...
}

adding in sleep(3) was enough between the collaborators call for it to work, so it slows things down "enough"

But the fact it was silently returning what appeared to be a legitimately empty result I did not catch until I was actually doing something and realized my script was lying to me.

JustSteveKing commented 2 years ago

I am actually looking into how I can manage this in general at the moment, both myself and Sam Carre are looking at what we can do for PHP HTTP and rate limiting and retrying