diff --git a/app/Jobs/DockerCleanupJob.php b/app/Jobs/DockerCleanupJob.php index a88b4c2f5..c8f1bd049 100644 --- a/app/Jobs/DockerCleanupJob.php +++ b/app/Jobs/DockerCleanupJob.php @@ -12,7 +12,6 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log; -use RuntimeException; class DockerCleanupJob implements ShouldBeEncrypted, ShouldQueue { @@ -27,20 +26,25 @@ public function __construct(public Server $server) {} public function handle(): void { try { - $isInprogress = false; - $this->server->applications()->each(function ($application) use (&$isInprogress) { - if ($application->isDeploymentInprogress()) { - $isInprogress = true; + // $isInprogress = false; + // $this->server->applications()->each(function ($application) use (&$isInprogress) { + // if ($application->isDeploymentInprogress()) { + // $isInprogress = true; - return; - } - }); + // return; + // } + // }); // if ($isInprogress) { // throw new RuntimeException('DockerCleanupJob: ApplicationDeploymentQueue is not empty, skipping...'); // } if (! $this->server->isFunctional()) { return; } + if ($this->server->is_force_cleanup_enabled) { + CleanupDocker::run($this->server); + + return; + } $this->usageBefore = $this->server->getDiskUsage(); ray('Usage before: '.$this->usageBefore); if ($this->usageBefore >= $this->server->settings->cleanup_after_percentage) { diff --git a/app/Jobs/ServerStatusJob.php b/app/Jobs/ServerStatusJob.php index bddafe2ba..64730c6fa 100644 --- a/app/Jobs/ServerStatusJob.php +++ b/app/Jobs/ServerStatusJob.php @@ -44,7 +44,7 @@ public function handle() } try { if ($this->server->isFunctional()) { - $this->cleanup(notify: false); + $this->cleanup(); $this->remove_unnecessary_coolify_yaml(); if ($this->server->isSentinelEnabled()) { $this->server->checkSentinel(); @@ -109,23 +109,24 @@ private function remove_unnecessary_coolify_yaml() } } - public function cleanup(bool $notify = false): void + public function cleanup(): void { + if ($this->server->settings->is_force_cleanup_enabled) { + DockerCleanupJob::dispatch($this->server); + + return; + } $this->disk_usage = $this->server->getDiskUsage(); if ($this->disk_usage >= $this->server->settings->cleanup_after_percentage) { - if ($notify) { - if ($this->server->high_disk_usage_notification_sent) { - ray('high disk usage notification already sent'); + DockerCleanupJob::dispatch($this->server); + if ($this->server->high_disk_usage_notification_sent) { + ray('high disk usage notification already sent'); - return; - } else { - $this->server->high_disk_usage_notification_sent = true; - $this->server->save(); - $this->server->team?->notify(new HighDiskUsage($this->server, $this->disk_usage, $this->server->settings->cleanup_after_percentage)); - } + return; } else { - DockerCleanupJob::dispatchSync($this->server); - $this->cleanup(notify: true); + $this->server->high_disk_usage_notification_sent = true; + $this->server->save(); + $this->server->team?->notify(new HighDiskUsage($this->server, $this->disk_usage, $this->server->settings->cleanup_after_percentage)); } } else { $this->server->high_disk_usage_notification_sent = false; diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php index 5616123a5..c2a55afcb 100644 --- a/app/Livewire/Server/Form.php +++ b/app/Livewire/Server/Form.php @@ -37,6 +37,7 @@ class Form extends Component 'server.settings.is_swarm_manager' => 'required|boolean', 'server.settings.is_swarm_worker' => 'required|boolean', 'server.settings.is_build_server' => 'required|boolean', + 'server.settings.is_force_cleanup_enabled' => 'required|boolean', 'server.settings.concurrent_builds' => 'required|integer|min:1', 'server.settings.dynamic_timeout' => 'required|integer|min:1', 'server.settings.is_metrics_enabled' => 'required|boolean', diff --git a/database/migrations/2024_07_18_123458_add_force_cleanup_server.php b/database/migrations/2024_07_18_123458_add_force_cleanup_server.php new file mode 100644 index 000000000..a33665bd0 --- /dev/null +++ b/database/migrations/2024_07_18_123458_add_force_cleanup_server.php @@ -0,0 +1,28 @@ +boolean('is_force_cleanup_enabled')->default(false)->after('is_sentinel_enabled'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('server_settings', function (Blueprint $table) { + $table->dropColumn('is_force_cleanup_enabled'); + }); + } +}; diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php index 5cba620dd..e10dec0d4 100644 --- a/resources/views/livewire/server/form.blade.php +++ b/resources/views/livewire/server/form.blade.php @@ -136,13 +136,32 @@ class="w-full mt-8 mb-4 font-bold box-without-bg bg-coollabs hover:bg-coollabs-1 @if ($server->isFunctional())

Settings

-
- - - +
+
+ @if ($server->settings->is_force_cleanup_enabled) +
+ +
+ @else + +
+ +
+ @endif +
+
+ + +

Sentinel