Improve backoff using exponential decay

This commit is contained in:
David Bomba 2023-01-29 11:51:57 +11:00
parent cdd71d60e8
commit 35775706be
4 changed files with 24 additions and 12 deletions

View File

@ -50,9 +50,7 @@ class NinjaMailerJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, MakesHash;
public $tries = 3; //number of retries
public $backoff = 30; //seconds to wait until retry
public $tries = 4; //number of retries
public $deleteWhenMissingModels = true;
@ -80,6 +78,11 @@ class NinjaMailerJob implements ShouldQueue
}
public function backoff()
{
return [30, 60, 180, 240];
}
public function handle()
{

View File

@ -38,9 +38,7 @@ class WebhookHandler implements ShouldQueue
private $company;
public $tries = 3; //number of retries
public $backoff = 10; //seconds to wait until retry
public $tries = 4; //number of retries
public $deleteWhenMissingModels = true;
@ -60,6 +58,11 @@ class WebhookHandler implements ShouldQueue
$this->includes = $includes;
}
public function backoff()
{
return [10, 30, 60, 180];
}
/**
* Execute the job.
*
@ -79,7 +82,7 @@ class WebhookHandler implements ShouldQueue
->where('event_id', $this->event_id)
->cursor()
->each(function ($subscription) {
$this->process($subscription);
});
@ -148,13 +151,14 @@ class WebhookHandler implements ShouldQueue
}
} catch (\Exception $e) {
nlog("429 occurred in the expcetion handler");
nlog("429 occurred in the exception handler");
nlog($e->getMessage());
SystemLogger::dispatch(
$e->getMessage(),
SystemLog::CATEGORY_WEBHOOK,
SystemLog::EVENT_WEBHOOK_RESPONSE,
SystemLog::EVENT_WEBHOOK_FAILURE,
SystemLog::TYPE_WEBHOOK_RESPONSE,
$this->resolveClient(),
$this->company,

View File

@ -69,6 +69,8 @@ class SystemLog extends Model
const EVENT_WEBHOOK_RESPONSE = 40;
const EVENT_WEBHOOK_SUCCESS = 41;
const EVENT_WEBHOOK_FAILURE = 42;
const EVENT_PDF_RESPONSE = 50;

View File

@ -41,9 +41,7 @@ class EmailMailer implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, MakesHash;
public $tries = 3; //number of retries
public $backoff = 30; //seconds to wait until retry
public $tries = 4; //number of retries
public $deleteWhenMissingModels = true;
@ -59,6 +57,11 @@ class EmailMailer implements ShouldQueue
public function __construct(public EmailService $email_service, public Mailable $email_mailable){}
public function backoff()
{
return [30, 60, 180, 240];
}
public function handle(): void
{
MultiDB::setDb($this->email_service->company->db);