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

View File

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

View File

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

View File

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