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
feat: server disabled by overflow
Andras Bacsai64fca99c2699
diff --git a/app/Jobs/ServerOverflowJob.php b/app/Jobs/ServerOverflowJob.phpnew file mode 100644index 0000000000..af7b7a9274--- /dev/null+++ b/app/Jobs/ServerOverflowJob.php@@ -0,0 +1,62 @@+<?php++namespace App\Jobs;++use App\Models\Team;+use App\Notifications\Server\DisabledDueToOverflow;+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 ServerOverflowJob implements ShouldQueue, ShouldBeEncrypted+{+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;++ public $tries = 4;+ public function backoff(): int+ {+ return isDev() ? 1 : 3;+ }+ public function __construct(public Team $team)+ {+ }+ public function middleware(): array+ {+ return [(new WithoutOverlapping($this->team->uuid))];+ }++ public function uniqueId(): int+ {+ return $this->team->uuid;+ }++ public function handle()+ {+ try {+ ray('ServerOverflowJob');+ $servers = $this->team->servers;+ $servers_count = $servers->count();+ $limit = $this->team->limits['serverLimit'];+ $number_of_servers_to_disable = $servers_count - $limit;+ ray($number_of_servers_to_disable, $servers_count, $limit);+ if ($number_of_servers_to_disable > 0) {+ ray('Disabling servers');+ $servers = $servers->sortBy('created_at');+ $servers_to_disable = $servers->take($number_of_servers_to_disable);+ $servers_to_disable->each(function ($server) {+ $server->disableServerDueToOverflow();+ $this->team->notify(new DisabledDueToOverflow($server));+ });+ }+ } catch (\Throwable $e) {+ send_internal_notification('ServerOverflowJob failed with: ' . $e->getMessage());+ ray($e->getMessage());+ return handleError($e);+ }+ }++}diff --git a/app/Models/Server.php b/app/Models/Server.phpindex 016efd5f7f..4272761a50 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -151,6 +151,11 @@ class Server extends BaseModel}return false;}+ public function disableServerDueToOverflow() {+ $this->settings->update([+ 'disabled_by_overflow' => true,+ ]);+ }public function isServerReady(int $tries = 3){if ($this->skipServer()) {diff --git a/app/Notifications/Server/DisabledDueToOverflow.php b/app/Notifications/Server/DisabledDueToOverflow.phpnew file mode 100644index 0000000000..957d9c866e--- /dev/null+++ b/app/Notifications/Server/DisabledDueToOverflow.php@@ -0,0 +1,63 @@+<?php++namespace App\Notifications\Server;++use App\Models\Server;+use Illuminate\Bus\Queueable;+use App\Notifications\Channels\DiscordChannel;+use App\Notifications\Channels\EmailChannel;+use App\Notifications\Channels\TelegramChannel;+use Illuminate\Contracts\Queue\ShouldQueue;+use Illuminate\Notifications\Messages\MailMessage;+use Illuminate\Notifications\Notification;++class DisabledDueToOverflow extends Notification implements ShouldQueue+{+ use Queueable;++ public $tries = 1;+ public function __construct(public Server $server)+ {+ }++ public function via(object $notifiable): array+ {+ $channels = [];+ $isEmailEnabled = isEmailEnabled($notifiable);+ $isDiscordEnabled = data_get($notifiable, 'discord_enabled');+ $isTelegramEnabled = data_get($notifiable, 'telegram_enabled');++ if ($isDiscordEnabled) {+ $channels[] = DiscordChannel::class;+ }+ if ($isEmailEnabled) {+ $channels[] = EmailChannel::class;+ }+ if ($isTelegramEnabled) {+ $channels[] = TelegramChannel::class;+ }+ return $channels;+ }++ public function toMail(): MailMessage+ {+ $mail = new MailMessage();+ $mail->subject("Coolify: Server ({$this->server->name}) disabled because it is not paid!");+ $mail->view('emails.server-disabled-due-to-overflow', [+ 'name' => $this->server->name,+ ]);+ return $mail;+ }++ public function toDiscord(): string+ {+ $message = "Coolify: Server ({$this->server->name}) disabled because it is not paid!\n All automations and integrations are stopped.\nPlease update your subscription to enable the server again [here](https://app.coolify.io/subsciprtions).";+ return $message;+ }+ public function toTelegram(): array+ {+ return [+ "message" => "Coolify: Server ({$this->server->name}) disabled because it is not paid!\n All automations and integrations are stopped.\nPlease update your subscription to enable the server again [here](https://app.coolify.io/subsciprtions)."+ ];+ }+}diff --git a/database/migrations/2024_02_25_222150_add_disabled_server_due_to_overflow.php b/database/migrations/2024_02_25_222150_add_disabled_server_due_to_overflow.phpnew file mode 100644index 0000000000..3d1b808ab4--- /dev/null+++ b/database/migrations/2024_02_25_222150_add_disabled_server_due_to_overflow.php@@ -0,0 +1,28 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('server_settings', function (Blueprint $table) {+ $table->boolean('disabled_by_overflow')->default(false);+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('server_settings', function (Blueprint $table) {+ $table->dropColumn('disabled_by_overflow');+ });+ }+};diff --git a/resources/views/emails/server-disabled-due-to-overflow.blade.php b/resources/views/emails/server-disabled-due-to-overflow.blade.phpnew file mode 100644index 0000000000..7cc43c354d--- /dev/null+++ b/resources/views/emails/server-disabled-due-to-overflow.blade.php@@ -0,0 +1,5 @@+<x-emails.layout>+Your server ({{ $name }}) disabled because it is not paid! All automations and integrations are stopped.++Please update your subscription to enable the server again [here](https://app.coolify.io/subsciprtions).+</x-emails.layout>diff --git a/routes/webhooks.php b/routes/webhooks.phpindex 03bbfd9994..e8fc647131 100644--- a/routes/webhooks.php+++ b/routes/webhooks.php@@ -3,6 +3,7 @@use App\Enums\ProcessStatus;use App\Jobs\ApplicationPullRequestUpdateJob;use App\Jobs\GithubAppPermissionJob;+use App\Jobs\ServerOverflowJob;use App\Jobs\SubscriptionInvoiceFailedJob;use App\Jobs\SubscriptionTrialEndedJob;use App\Jobs\SubscriptionTrialEndsSoonJob;@@ -882,6 +883,7 @@ Route::post('/payments/stripe/events', function () {$team->update(['custom_server_limit' => $quantity,]);+ ServerOverflowJob::dispatch($team);}$subscription->update(['stripe_feedback' => $feedback,