Skip to content

Commit

Permalink
set correct attempt when retry notification job
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Kaufmann committed Oct 17, 2022
1 parent f1b3c26 commit 97438d3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Loggers/SentNotificationLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ public function logSendingNotification(NotificationSending $event): ?SentNotific
return null;
}

$event->notification::$attempt += 1;
$currentAttempt = SentNotificationLog::query()
->where('notification_id', $event->notification->id)
->where('channel', $event->channel)
->max('attempt');

// when you retry a job after it failed after several tries, the attempt of the instance will be reset as
// it will be pushed as a new instance with the same notification id to the queue.
// Therefor we need to increment the attempt manually by looking it up in the logs table.
if ($currentAttempt > $event->notification::$attempt) {
$event->notification::$attempt = $currentAttempt + 1;
} else {
$event->notification::$attempt++;
}

/** @var SentNotificationLog $notification */
$notification = SentNotificationLog::create([
Expand Down

0 comments on commit 97438d3

Please sign in to comment.