From 1452cdf5ad830ee90eba7c92428e59e3489879b3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 18 Sep 2023 15:19:27 +0200 Subject: [PATCH] fix: send internal notifications of email errors --- app/Http/Livewire/Boarding/Index.php | 8 ----- app/Jobs/ContainerStatusJob.php | 1 - .../Application/DeploymentFailed.php | 2 +- .../Application/DeploymentSuccess.php | 2 +- .../Application/StatusChanged.php | 2 +- app/Notifications/Channels/EmailChannel.php | 36 +++++++++++-------- app/Notifications/Database/BackupFailed.php | 4 +-- app/Notifications/Database/BackupSuccess.php | 4 +-- 8 files changed, 26 insertions(+), 33 deletions(-) diff --git a/app/Http/Livewire/Boarding/Index.php b/app/Http/Livewire/Boarding/Index.php index 7c42df536..c1ec202cf 100644 --- a/app/Http/Livewire/Boarding/Index.php +++ b/app/Http/Livewire/Boarding/Index.php @@ -69,14 +69,6 @@ public function explanation() public function restartBoarding() { - // if ($this->selectedServerType !== 'localhost') { - // if ($this->createdServer) { - // $this->createdServer->delete(); - // } - // if ($this->createdPrivateKey) { - // $this->createdPrivateKey->delete(); - // } - // } return redirect()->route('boarding'); } public function skipBoarding() diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index 22f0e2f10..527dcad67 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -86,7 +86,6 @@ public function handle(): void $this->server->team->notify(new ContainerRestarted('coolify-proxy', $this->server)); } } else { - ray($foundProxyContainer); $this->server->proxy->status = data_get($foundProxyContainer, 'State.Status'); $this->server->save(); } diff --git a/app/Notifications/Application/DeploymentFailed.php b/app/Notifications/Application/DeploymentFailed.php index efac09097..f97fbc77e 100644 --- a/app/Notifications/Application/DeploymentFailed.php +++ b/app/Notifications/Application/DeploymentFailed.php @@ -14,7 +14,7 @@ class DeploymentFailed extends Notification implements ShouldQueue { use Queueable; - public $tries = 5; + public $tries = 1; public Application $application; public ?ApplicationPreview $preview = null; diff --git a/app/Notifications/Application/DeploymentSuccess.php b/app/Notifications/Application/DeploymentSuccess.php index 3b2d6e17f..053ae7a2b 100644 --- a/app/Notifications/Application/DeploymentSuccess.php +++ b/app/Notifications/Application/DeploymentSuccess.php @@ -14,7 +14,7 @@ class DeploymentSuccess extends Notification implements ShouldQueue { use Queueable; - public $tries = 5; + public $tries = 1; public Application $application; public ApplicationPreview|null $preview = null; diff --git a/app/Notifications/Application/StatusChanged.php b/app/Notifications/Application/StatusChanged.php index 90ac92304..064c347d0 100644 --- a/app/Notifications/Application/StatusChanged.php +++ b/app/Notifications/Application/StatusChanged.php @@ -13,7 +13,7 @@ class StatusChanged extends Notification implements ShouldQueue { use Queueable; - public $tries = 5; + public $tries = 1; public Application $application; public string $application_name; diff --git a/app/Notifications/Channels/EmailChannel.php b/app/Notifications/Channels/EmailChannel.php index 1d04c07d3..c84ea63e4 100644 --- a/app/Notifications/Channels/EmailChannel.php +++ b/app/Notifications/Channels/EmailChannel.php @@ -12,23 +12,29 @@ class EmailChannel { public function send(SendsEmail $notifiable, Notification $notification): void { - $this->bootConfigs($notifiable); - $recepients = $notifiable->getRecepients($notification); + try { + $this->bootConfigs($notifiable); + $recepients = $notifiable->getRecepients($notification); + ray($recepients); + if (count($recepients) === 0) { + throw new Exception('No email recipients found'); + } - if (count($recepients) === 0) { - throw new Exception('No email recipients found'); + $mailMessage = $notification->toMail($notifiable); + throw new Exception('EmailChannel is disabled'); + Mail::send( + [], + [], + fn (Message $message) => $message + ->to($recepients) + ->subject($mailMessage->subject) + ->html((string)$mailMessage->render()) + ); + } catch (Exception $e) { + ray($e->getMessage()); + send_internal_notification("EmailChannel error: {$e->getMessage()}. Failed to send email to: " . implode(', ', $recepients) . " with subject: {$mailMessage->subject}"); + throw $e; } - - $mailMessage = $notification->toMail($notifiable); - ray("Sending email to: " . implode(', ', $recepients) . " with subject: {$mailMessage->subject}"); - Mail::send( - [], - [], - fn (Message $message) => $message - ->to($recepients) - ->subject($mailMessage->subject) - ->html((string)$mailMessage->render()) - ); } private function bootConfigs($notifiable): void diff --git a/app/Notifications/Database/BackupFailed.php b/app/Notifications/Database/BackupFailed.php index 960232f9c..482b27977 100644 --- a/app/Notifications/Database/BackupFailed.php +++ b/app/Notifications/Database/BackupFailed.php @@ -3,8 +3,6 @@ namespace App\Notifications\Database; use App\Models\ScheduledDatabaseBackup; -use App\Notifications\Channels\DiscordChannel; -use App\Notifications\Channels\EmailChannel; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; @@ -14,7 +12,7 @@ class BackupFailed extends Notification implements ShouldQueue { use Queueable; - public $tries = 5; + public $tries = 1; public string $name; public string $frequency; diff --git a/app/Notifications/Database/BackupSuccess.php b/app/Notifications/Database/BackupSuccess.php index bac96ae35..0378baf96 100644 --- a/app/Notifications/Database/BackupSuccess.php +++ b/app/Notifications/Database/BackupSuccess.php @@ -3,8 +3,6 @@ namespace App\Notifications\Database; use App\Models\ScheduledDatabaseBackup; -use App\Notifications\Channels\DiscordChannel; -use App\Notifications\Channels\EmailChannel; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; @@ -14,7 +12,7 @@ class BackupSuccess extends Notification implements ShouldQueue { use Queueable; - public $tries = 5; + public $tries = 1; public string $name; public string $frequency;