Improves for interacting with gmail API

This commit is contained in:
David Bomba 2022-01-23 23:18:09 +11:00
parent 56186840f2
commit ac0efe9ead
3 changed files with 20 additions and 3 deletions

View File

@ -76,8 +76,25 @@ class GmailTransport extends Transport
} }
/**
* Google is very strict with their
* sending limits, if we hit 429s, sleep and
* retry again later.
*/
try{
$this->gmail->send(); $this->gmail->send();
}
catch(\Google\Service\Exception $e)
{
nlog("gmail exception");
nlog($e->getErrors());
sleep(5);
$this->gmail->send();
}
$this->sendPerformed($message); $this->sendPerformed($message);
return $this->numberOfRecipients($message); return $this->numberOfRecipients($message);

View File

@ -219,7 +219,7 @@ class NinjaMailerJob implements ShouldQueue
$google->getClient()->setAccessToken(json_encode($user->oauth_user_token)); $google->getClient()->setAccessToken(json_encode($user->oauth_user_token));
//need to slow down gmail requests otherwise we hit 429's //need to slow down gmail requests otherwise we hit 429's
sleep(rand(1,3)); sleep(rand(2,6));
} }
catch(\Exception $e) { catch(\Exception $e) {
$this->logMailError('Gmail Token Invalid', $this->company->clients()->first()); $this->logMailError('Gmail Token Invalid', $this->company->clients()->first());

View File

@ -13,7 +13,7 @@
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::group(['middleware' => ['throttle:10,1', 'api_secret_check']], function () { Route::group(['middleware' => ['throttle:300,1', 'api_secret_check']], function () {
Route::post('api/v1/signup', 'AccountController@store')->name('signup.submit'); Route::post('api/v1/signup', 'AccountController@store')->name('signup.submit');
Route::post('api/v1/oauth_login', 'Auth\LoginController@oauthApiLogin'); Route::post('api/v1/oauth_login', 'Auth\LoginController@oauthApiLogin');
}); });