2023-08-10 19:00:02 +00:00
< ? php
namespace App\Notifications\Database ;
use App\Models\ScheduledDatabaseBackup ;
2024-10-01 19:46:56 +00:00
use App\Notifications\Dto\DiscordMessage ;
2023-08-10 19:00:02 +00:00
use Illuminate\Bus\Queueable ;
use Illuminate\Contracts\Queue\ShouldQueue ;
use Illuminate\Notifications\Messages\MailMessage ;
use Illuminate\Notifications\Notification ;
class BackupFailed extends Notification implements ShouldQueue
{
use Queueable ;
2024-04-29 07:38:45 +00:00
public $backoff = 10 ;
2024-06-10 20:43:34 +00:00
2024-04-29 07:38:45 +00:00
public $tries = 2 ;
2024-06-10 20:43:34 +00:00
2023-09-01 13:52:18 +00:00
public string $name ;
2024-06-10 20:43:34 +00:00
2023-09-01 13:52:18 +00:00
public string $frequency ;
2023-08-10 19:00:02 +00:00
2024-04-29 07:38:45 +00:00
public function __construct ( ScheduledDatabaseBackup $backup , public $database , public $output , public $database_name )
2023-08-10 19:00:02 +00:00
{
2024-11-22 10:16:01 +00:00
$this -> onQueue ( 'high' );
2023-09-01 13:52:18 +00:00
$this -> name = $database -> name ;
$this -> frequency = $backup -> frequency ;
2023-08-10 19:00:02 +00:00
}
public function via ( object $notifiable ) : array
{
2024-04-29 07:38:45 +00:00
return setNotificationChannels ( $notifiable , 'database_backups' );
2023-08-10 19:00:02 +00:00
}
public function toMail () : MailMessage
{
2024-07-24 12:27:21 +00:00
$mail = new MailMessage ;
2023-10-10 11:10:43 +00:00
$mail -> subject ( " Coolify: [ACTION REQUIRED] Backup FAILED for { $this -> database -> name } " );
2023-09-01 13:52:18 +00:00
$mail -> view ( 'emails.backup-failed' , [
'name' => $this -> name ,
2024-04-25 10:09:46 +00:00
'database_name' => $this -> database_name ,
2023-09-01 13:52:18 +00:00
'frequency' => $this -> frequency ,
'output' => $this -> output ,
]);
2024-06-10 20:43:34 +00:00
2023-08-10 19:00:02 +00:00
return $mail ;
}
2024-10-01 19:46:56 +00:00
public function toDiscord () : DiscordMessage
2023-08-10 19:00:02 +00:00
{
2024-10-01 19:46:56 +00:00
$message = new DiscordMessage (
2024-10-21 20:40:43 +00:00
title : ':cross_mark: Database backup failed' ,
description : " Database backup for { $this -> name } (db: { $this -> database_name } ) has FAILED. " ,
2024-10-01 19:46:56 +00:00
color : DiscordMessage :: errorColor (),
isCritical : true ,
);
2024-10-21 20:40:43 +00:00
$message -> addField ( 'Frequency' , $this -> frequency , true );
2024-10-01 19:46:56 +00:00
$message -> addField ( 'Output' , $this -> output );
return $message ;
2023-08-10 19:00:02 +00:00
}
2024-06-10 20:43:34 +00:00
2023-09-06 12:31:38 +00:00
public function toTelegram () : array
{
2024-04-29 07:38:45 +00:00
$message = " Coolify: Database backup for { $this -> name } (db: { $this -> database_name } ) with frequency of { $this -> frequency } was FAILED. \n \n Reason: \n { $this -> output } " ;
2024-06-10 20:43:34 +00:00
2023-09-06 12:31:38 +00:00
return [
2024-06-10 20:43:34 +00:00
'message' => $message ,
2023-09-06 12:31:38 +00:00
];
}
2023-08-10 19:00:02 +00:00
}