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: Add execution log to dockerCleanupJob
peaklabs-dev42f883cc5bf3
diff --git a/app/Jobs/DockerCleanupJob.php b/app/Jobs/DockerCleanupJob.phpindex 103c137b9f..30fe6c5bcf 100644--- a/app/Jobs/DockerCleanupJob.php+++ b/app/Jobs/DockerCleanupJob.php@@ -3,6 +3,8 @@namespace App\Jobs;use App\Actions\Server\CleanupDocker;+use App\Events\DockerCleanupDone;+use App\Models\DockerCleanupExecution;use App\Models\Server;use App\Notifications\Server\DockerCleanupFailed;use App\Notifications\Server\DockerCleanupSuccess;@@ -24,6 +26,8 @@ class DockerCleanupJob implements ShouldBeEncrypted, ShouldQueuepublic ?string $usageBefore = null;+ public ?DockerCleanupExecution $execution_log = null;+public function middleware(): array{return [(new WithoutOverlapping($this->server->uuid))->dontRelease()];@@ -38,35 +42,81 @@ class DockerCleanupJob implements ShouldBeEncrypted, ShouldQueuereturn;}+ $this->execution_log = DockerCleanupExecution::create([+ 'server_id' => $this->server->id,+ ]);+$this->usageBefore = $this->server->getDiskUsage();if ($this->manualCleanup || $this->server->settings->force_docker_cleanup) {- CleanupDocker::run(server: $this->server);+ $cleanup_log = CleanupDocker::run(server: $this->server);$usageAfter = $this->server->getDiskUsage();- $this->server->team?->notify(new DockerCleanupSuccess($this->server, ($this->manualCleanup ? 'Manual' : 'Forced').' Docker cleanup job executed successfully. Disk usage before: '.$this->usageBefore.'%, Disk usage after: '.$usageAfter.'%.'));+ $message = ($this->manualCleanup ? 'Manual' : 'Forced').' Docker cleanup job executed successfully. Disk usage before: '.$this->usageBefore.'%, Disk usage after: '.$usageAfter.'%.';++ $this->execution_log->update([+ 'status' => 'success',+ 'message' => $message,+ 'cleanup_log' => $cleanup_log,+ ]);++ $this->server->team?->notify(new DockerCleanupSuccess($this->server, $message));+ event(new DockerCleanupDone($this->execution_log));return;}if (str($this->usageBefore)->isEmpty() || $this->usageBefore === null || $this->usageBefore === 0) {- CleanupDocker::run(server: $this->server);- $this->server->team?->notify(new DockerCleanupSuccess($this->server, 'Docker cleanup job executed successfully, but no disk usage could be determined.'));+ $cleanup_log = CleanupDocker::run(server: $this->server);+ $message = 'Docker cleanup job executed successfully, but no disk usage could be determined.';++ $this->execution_log->update([+ 'status' => 'success',+ 'message' => $message,+ 'cleanup_log' => $cleanup_log,+ ]);++ $this->server->team?->notify(new DockerCleanupSuccess($this->server, $message));+ event(new DockerCleanupDone($this->execution_log));}if ($this->usageBefore >= $this->server->settings->docker_cleanup_threshold) {- CleanupDocker::run(server: $this->server);+ $cleanup_log = CleanupDocker::run(server: $this->server);$usageAfter = $this->server->getDiskUsage();$diskSaved = $this->usageBefore - $usageAfter;if ($diskSaved > 0) {- $this->server->team?->notify(new DockerCleanupSuccess($this->server, 'Saved '.$diskSaved.'% disk space. Disk usage before: '.$this->usageBefore.'%, Disk usage after: '.$usageAfter.'%.'));+ $message = 'Saved '.$diskSaved.'% disk space. Disk usage before: '.$this->usageBefore.'%, Disk usage after: '.$usageAfter.'%.';} else {- $this->server->team?->notify(new DockerCleanupSuccess($this->server, 'Docker cleanup job executed successfully, but no disk space was saved. Disk usage before: '.$this->usageBefore.'%, Disk usage after: '.$usageAfter.'%.'));+ $message = 'Docker cleanup job executed successfully, but no disk space was saved. Disk usage before: '.$this->usageBefore.'%, Disk usage after: '.$usageAfter.'%.';}++ $this->execution_log->update([+ 'status' => 'success',+ 'message' => $message,+ 'cleanup_log' => $cleanup_log,+ ]);++ $this->server->team?->notify(new DockerCleanupSuccess($this->server, $message));+ event(new DockerCleanupDone($this->execution_log));} else {- $this->server->team?->notify(new DockerCleanupSuccess($this->server, 'No cleanup needed for '.$this->server->name));+ $message = 'No cleanup needed for '.$this->server->name;++ $this->execution_log->update([+ 'status' => 'success',+ 'message' => $message,+ ]);++ $this->server->team?->notify(new DockerCleanupSuccess($this->server, $message));+ event(new DockerCleanupDone($this->execution_log));}} catch (\Throwable $e) {+ if ($this->execution_log) {+ $this->execution_log->update([+ 'status' => 'failed',+ 'message' => $e->getMessage(),+ ]);+ event(new DockerCleanupDone($this->execution_log));+ }$this->server->team?->notify(new DockerCleanupFailed($this->server, 'Docker cleanup job failed with the following error: '.$e->getMessage()));throw $e;}