An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix: remove success application deployment job wip: daily backup status
Andras Bacsai2eb7712e092f
diff --git a/app/Console/Commands/Emails.php b/app/Console/Commands/Emails.phpindex 86f317c96f..db4122b65f 100644--- a/app/Console/Commands/Emails.php+++ b/app/Console/Commands/Emails.php@@ -2,10 +2,12 @@namespace App\Console\Commands;+use App\Jobs\DatabaseBackupStatusJob;use App\Jobs\SendConfirmationForWaitlistJob;use App\Models\Application;use App\Models\ApplicationPreview;use App\Models\ScheduledDatabaseBackup;+use App\Models\ScheduledDatabaseBackupExecution;use App\Models\Server;use App\Models\StandalonePostgresql;use App\Models\Team;@@ -15,6 +17,7 @@ use App\Notifications\Application\DeploymentSuccess;use App\Notifications\Application\StatusChanged;use App\Notifications\Database\BackupFailed;use App\Notifications\Database\BackupSuccess;+use App\Notifications\Database\DailyBackup;use App\Notifications\Test;use Exception;use Illuminate\Console\Command;@@ -54,6 +57,8 @@ class Emails extends Commandoptions: ['updates' => 'Send Update Email to all users','emails-test' => 'Test',+ 'database-backup-statuses-daily' => 'Database - Backup Statuses (Daily)',+ 'application-deployment-success-daily' => 'Application - Deployment Success (Daily)','application-deployment-success' => 'Application - Deployment Success','application-deployment-failed' => 'Application - Deployment Failed','application-status-changed' => 'Application - Status Changed',@@ -67,8 +72,12 @@ class Emails extends Command],);$emailsGathered = ['realusers-before-trial', 'realusers-server-lost-connection'];- if (!in_array($type, $emailsGathered)) {- $this->email = text('Email Address to send to');+ if (isDev()) {+ $this->email = "[email protected]";+ } else {+ if (!in_array($type, $emailsGathered)) {+ $this->email = text('Email Address to send to:');+ }}set_transanctional_email_settings();@@ -102,7 +111,7 @@ class Emails extends Command$unsubscribeUrl = route('unsubscribe.marketing.emails', ['token' => encrypt($email),]);- $this->mail->view('emails.updates',["unsubscribeUrl" => $unsubscribeUrl]);+ $this->mail->view('emails.updates', ["unsubscribeUrl" => $unsubscribeUrl]);$this->sendEmail($email);}}@@ -111,6 +120,35 @@ class Emails extends Command$this->mail = (new Test())->toMail();$this->sendEmail();break;+ case 'database-backup-statuses-daily':+ $scheduled_backups = ScheduledDatabaseBackup::all();+ $databases = collect();+ foreach ($scheduled_backups as $scheduled_backup) {+ $last_days_backups = $scheduled_backup->get_last_days_backup_status();+ if ($last_days_backups->isEmpty()) {+ continue;+ }+ $failed = $last_days_backups->where('status', 'failed');+ $database = $scheduled_backup->database;+ $databases->put($database->name, [+ 'failed_count' => $failed->count(),+ ]);+ }+ $this->mail = (new DailyBackup($databases))->toMail();+ $this->sendEmail();+ break;+ case 'application-deployment-success-daily':+ $applications = Application::all();+ foreach ($applications as $application) {+ $deployments = $application->get_last_days_deployments();+ ray($deployments);+ if ($deployments->isEmpty()) {+ continue;+ }+ $this->mail = (new DeploymentSuccess($application, 'test'))->toMail();+ $this->sendEmail();+ }+ break;case 'application-deployment-success':$application = Application::all()->first();$this->mail = (new DeploymentSuccess($application, 'test'))->toMail();diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex becf6387a9..cded183aa8 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -1651,7 +1651,7 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");if (!$this->only_this_server) {$this->deploy_to_additional_destinations();}- $this->application->environment->project->team?->notify(new DeploymentSuccess($this->application, $this->deployment_uuid, $this->preview));+ // $this->application->environment->project->team?->notify(new DeploymentSuccess($this->application, $this->deployment_uuid, $this->preview));}}diff --git a/app/Jobs/DatabaseBackupStatusJob.php b/app/Jobs/DatabaseBackupStatusJob.phpnew file mode 100644index 0000000000..b92ed13e94--- /dev/null+++ b/app/Jobs/DatabaseBackupStatusJob.php@@ -0,0 +1,74 @@+<?php++namespace App\Jobs;++use App\Models\ScheduledDatabaseBackup;+use App\Models\Server;+use App\Models\Team;+use App\Notifications\Database\DailyBackup;+use App\Notifications\Server\HighDiskUsage;+use Illuminate\Bus\Queueable;+use Illuminate\Contracts\Queue\ShouldBeEncrypted;+use Illuminate\Contracts\Queue\ShouldQueue;+use Illuminate\Foundation\Bus\Dispatchable;+use Illuminate\Queue\InteractsWithQueue;+use Illuminate\Queue\Middleware\WithoutOverlapping;+use Illuminate\Queue\SerializesModels;++class DatabaseBackupStatusJob implements ShouldQueue, ShouldBeEncrypted+{+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;++ public $tries = 1;++ public function __construct()+ {+ }++ public function handle()+ {+ // $teams = Team::all();+ // foreach ($teams as $team) {+ // $scheduled_backups = $team->scheduledDatabaseBackups()->get();+ // if ($scheduled_backups->isEmpty()) {+ // continue;+ // }+ // foreach ($scheduled_backups as $scheduled_backup) {+ // $last_days_backups = $scheduled_backup->get_last_days_backup_status();+ // if ($last_days_backups->isEmpty()) {+ // continue;+ // }+ // $failed = $last_days_backups->where('status', 'failed');+ // }+ // }+++++++++ // $scheduled_backups = ScheduledDatabaseBackup::all();+ // $databases = collect();+ // $teams = collect();+ // foreach ($scheduled_backups as $scheduled_backup) {+ // $last_days_backups = $scheduled_backup->get_last_days_backup_status();+ // if ($last_days_backups->isEmpty()) {+ // continue;+ // }+ // $failed = $last_days_backups->where('status', 'failed');+ // $database = $scheduled_backup->database;+ // $team = $database->team();+ // $teams->put($team->id, $team);+ // $databases->put("{$team->id}:{$database->name}", [+ // 'failed_count' => $failed->count(),+ // ]);+ // }+ // foreach ($databases as $name => $database) {+ // [$team_id, $name] = explode(':', $name);+ // $team = $teams->get($team_id);+ // $team?->notify(new DailyBackup($databases));+ // }+ }+}diff --git a/app/Models/Application.php b/app/Models/Application.phpindex 4c9f3e1af2..4cb9412154 100644--- a/app/Models/Application.php+++ b/app/Models/Application.php@@ -65,7 +65,8 @@ class Application extends BaseModelreturn $this->belongsToMany(StandaloneDocker::class, 'additional_destinations')->withPivot('server_id', 'status');}- public function is_public_repository(): bool {+ public function is_public_repository(): bool+ {if (data_get($this, 'source.is_public')) {return true;}@@ -401,7 +402,10 @@ class Application extends BaseModel}return false;}-+ public function get_last_days_deployments()+ {+ return ApplicationDeploymentQueue::where('application_id', $this->id)->where('created_at', '>=', now()->subDays(7))->orderBy('created_at', 'desc')->get();+ }public function deployments(int $skip = 0, int $take = 10){$deployments = ApplicationDeploymentQueue::where('application_id', $this->id)->orderBy('created_at', 'desc');diff --git a/app/Models/ScheduledDatabaseBackup.php b/app/Models/ScheduledDatabaseBackup.phpindex 5c41fc4dc8..2cf62cac28 100644--- a/app/Models/ScheduledDatabaseBackup.php+++ b/app/Models/ScheduledDatabaseBackup.php@@ -30,4 +30,8 @@ class ScheduledDatabaseBackup extends BaseModel{return $this->belongsTo(S3Storage::class, 's3_storage_id');}+ public function get_last_days_backup_status($days = 7)+ {+ return $this->hasMany(ScheduledDatabaseBackupExecution::class)->where('created_at', '>=', now()->subDays($days))->get();+ }}diff --git a/app/Notifications/Database/DailyBackup.php b/app/Notifications/Database/DailyBackup.phpnew file mode 100644index 0000000000..dfa508fbd9--- /dev/null+++ b/app/Notifications/Database/DailyBackup.php@@ -0,0 +1,50 @@+<?php++namespace App\Notifications\Database;++use App\Models\ScheduledDatabaseBackup;+use App\Notifications\Channels\DiscordChannel;+use App\Notifications\Channels\TelegramChannel;+use Illuminate\Bus\Queueable;+use Illuminate\Contracts\Queue\ShouldQueue;+use Illuminate\Notifications\Channels\MailChannel;+use Illuminate\Notifications\Messages\MailMessage;+use Illuminate\Notifications\Notification;++class DailyBackup extends Notification implements ShouldQueue+{+ use Queueable;++ public $tries = 1;++ public function __construct(public $databases)+ {+ }++ public function via(object $notifiable): array+ {+ return [DiscordChannel::class, TelegramChannel::class, MailChannel::class];+ }++ public function toMail(): MailMessage+ {+ $mail = new MailMessage();+ $mail->subject("Coolify: Daily backup statuses");+ $mail->view('emails.daily-backup', [+ 'databases' => $this->databases,+ ]);+ return $mail;+ }++ public function toDiscord(): string+ {+ return "Coolify: Daily backup statuses";+ }+ public function toTelegram(): array+ {+ $message = "Coolify: Daily backup statuses";+ return [+ "message" => $message,+ ];+ }+}diff --git a/resources/views/emails/daily-backup.blade.php b/resources/views/emails/daily-backup.blade.phpnew file mode 100644index 0000000000..25d8873872--- /dev/null+++ b/resources/views/emails/daily-backup.blade.php@@ -0,0 +1,19 @@+<x-emails.layout>+@foreach ($databases as $database_name => $databases)++@if(data_get($databases,'failed_count') > 0)++<div style="color:red">++"{{ $database_name }}" backups: There were some failed backups. Please login and check the logs for more details.++</div>++@else++"{{ $database_name }}" backups: All backups were successful.++@endif++@endforeach+</x-emails.layout>