diff --git a/app/Livewire/Admin/Maintenance.php b/app/Livewire/Admin/Maintenance.php index be73703..14b4472 100644 --- a/app/Livewire/Admin/Maintenance.php +++ b/app/Livewire/Admin/Maintenance.php @@ -204,11 +204,23 @@ class Maintenance extends Component return; } + // Claim the row, then dispatch. If dispatch fails, release the claim + // immediately (delete if we created it, else restore the prior attempt + // time) so a resend can retry right away instead of waiting out the TTL. + $wasNew = $delivery->wasRecentlyCreated; + $priorUpdatedAt = $delivery->updated_at; $delivery->forceFill(['updated_at' => now()])->save(); $mail->notificationId = $delivery->id; - Mail::to($customer->email) - ->locale($customer->locale ?: config('app.locale')) - ->queue($mail); + + try { + Mail::to($customer->email) + ->locale($customer->locale ?: config('app.locale')) + ->queue($mail); + } catch (\Throwable $e) { + $wasNew ? $delivery->delete() : $delivery->forceFill(['updated_at' => $priorUpdatedAt])->save(); + + throw $e; + } } public function render()