mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Adjustments for GMail 429 handling
This commit is contained in:
parent
5123c9be6c
commit
9c7f1e888f
@ -64,23 +64,23 @@ class GmailTransport extends AbstractTransport
|
||||
|
||||
$body->setRaw($this->base64_encode($bcc_list.$message->toString()));
|
||||
|
||||
try {
|
||||
// try {
|
||||
$service->users_messages->send('me', $body, []);
|
||||
} catch(\Google\Service\Exception $e) {
|
||||
/* Need to slow down */
|
||||
if ($e->getCode() == '429') {
|
||||
nlog("429 google - retrying ");
|
||||
// } catch(\Google\Service\Exception $e) {
|
||||
// /* Need to slow down */
|
||||
// if ($e->getCode() == '429') {
|
||||
// nlog("429 google - retrying ");
|
||||
|
||||
sleep(rand(3,8));
|
||||
// sleep(rand(3,8));
|
||||
|
||||
try {
|
||||
$service->users_messages->send('me', $body, []);
|
||||
} catch(\Google\Service\Exception $e) {
|
||||
// try {
|
||||
// $service->users_messages->send('me', $body, []);
|
||||
// } catch(\Google\Service\Exception $e) {
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private function base64_encode($data)
|
||||
|
@ -164,7 +164,20 @@ class NinjaMailerJob implements ShouldQueue
|
||||
$this->cleanUpMailers();
|
||||
$this->logMailError($e->getMessage(), $this->company->clients()->first());
|
||||
return;
|
||||
} catch (\Exception | \Google\Service\Exception $e) {
|
||||
}
|
||||
catch(\Google\Service\Exception $e){
|
||||
|
||||
if ($e->getCode() == '429') {
|
||||
|
||||
$message = "Google rate limiting triggered, we are queueing based on GMail requirements.";
|
||||
$this->logMailError($message, $this->company->clients()->first());
|
||||
sleep(rand(1, 2));
|
||||
$this->release(900);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
nlog("Mailer failed with {$e->getMessage()}");
|
||||
$message = $e->getMessage();
|
||||
|
||||
@ -221,8 +234,7 @@ class NinjaMailerJob implements ShouldQueue
|
||||
}
|
||||
|
||||
/* Releasing immediately does not add in the backoff */
|
||||
sleep(rand(5, 10));
|
||||
|
||||
sleep(rand(2, 3));
|
||||
$this->release($this->backoff()[$this->attempts() - 1]);
|
||||
}
|
||||
|
||||
|
@ -302,7 +302,21 @@ class Email implements ShouldQueue
|
||||
$this->cleanUpMailers();
|
||||
$this->logMailError($e->getMessage(), $this->company->clients()->first());
|
||||
return;
|
||||
} catch (\Exception | \RuntimeException | \Google\Service\Exception $e) {
|
||||
}
|
||||
catch(\Google\Service\Exception $e){
|
||||
|
||||
if ($e->getCode() == '429') {
|
||||
|
||||
$message = "Google rate limiting triggered, we are queueing based on GMail requirements.";
|
||||
$this->logMailError($message, $this->company->clients()->first());
|
||||
sleep(rand(1, 2));
|
||||
$this->release(900);
|
||||
$message = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (\Exception | \RuntimeException $e) {
|
||||
nlog("Mailer failed with {$e->getMessage()}");
|
||||
$message = $e->getMessage();
|
||||
|
||||
|
@ -166,9 +166,9 @@ class EmailDefaults
|
||||
private function setBody(): self
|
||||
{
|
||||
|
||||
if (strlen($this->email->email_object->body) > 3) {
|
||||
if (strlen($this->email->email_object->body ?? '') > 3) {
|
||||
// A Custom Message has been set in the email screen.
|
||||
} elseif (strlen($this->email->email_object->settings?->{$this->email->email_object->email_template_body}) > 3) {
|
||||
} elseif (strlen($this->email->email_object->settings?->{$this->email->email_object->email_template_body} ?? '') > 3) {
|
||||
// A body has been saved in the settings.
|
||||
$this->email->email_object->body = $this->email->email_object->settings?->{$this->email->email_object->email_template_body};
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user