- Notifications
You must be signed in to change notification settings - Fork11.7k
-
Sometimes I don't want to throw an exception because that ends up being noise in sentry. Right now I do this: Is there a better way? |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment
-
Short answer: No, Laravel doesn't have a built-in method for this. When you call You could: // In your job classprotectedfunctionreleaseWithBackoff():void{$delay =$this->getBackoffDelay();$this->release($delay);}protectedfunctiongetBackoffDelay():int{$backoff =method_exists($this,'backoff') ?$this->backoff() : [];if (is_array($backoff)) {// Use attempt - 1 since attempts() is 1-indexedreturn$backoff[$this->attempts() -1] ??end($backoff) ?:0; }return (int)$backoff;} Or create a reusable trait: trait ReleasesWithBackoff{protectedfunctionreleaseWithBackoff(?int$jitter =null):void {$delay =$this->calculateBackoffDelay();if ($jitter) {$delay +=random_int(0,$jitter); }$this->release($delay); }protectedfunctioncalculateBackoffDelay():int {$backoff =method_exists($this,'backoff') ?$this->backoff() : [];$attempt =$this->attempts();if (is_array($backoff)) {return$backoff[$attempt -1] ??end($backoff) ?:0; }return (int)$backoff; }} |
BetaWas this translation helpful?Give feedback.
All reactions
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment