From 3dd36a22717b954c30b4ad339783cd26ef5b229a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 22 Nov 2023 15:18:37 +0100 Subject: [PATCH] Fix container status handling and notifications --- app/Jobs/ContainerStatusJob.php | 18 +++++++----------- bootstrap/helpers/shared.php | 2 +- config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index a45bebf8e..79265f7a1 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -35,17 +35,13 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted return $this->server->id; } - public function handle(): void + public function handle() { // ray("checking container statuses for {$this->server->id}"); try { if (!$this->server->isServerReady()) { return; }; - $containers = instant_remote_process(["docker container ls -q"], $this->server); - if (!$containers) { - return; - } $containers = instant_remote_process(["docker container inspect $(docker container ls -q) --format '{{json .}}'"], $this->server); $containers = format_docker_command_output_to_json($containers); $applications = $this->server->applications(); @@ -167,7 +163,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted } else { $url = null; } - $this->server->team->notify(new ContainerStopped($containerName, $this->server, $url)); + $this->server->team?->notify(new ContainerStopped($containerName, $this->server, $url)); $exitedService->update(['status' => 'exited']); } @@ -194,7 +190,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted $url = null; } - $this->server->team->notify(new ContainerStopped($containerName, $this->server, $url)); + $this->server->team?->notify(new ContainerStopped($containerName, $this->server, $url)); } $notRunningApplicationPreviews = $previews->pluck('id')->diff($foundApplicationPreviews); foreach ($notRunningApplicationPreviews as $previewId) { @@ -219,7 +215,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted $url = null; } - $this->server->team->notify(new ContainerStopped($containerName, $this->server, $url)); + $this->server->team?->notify(new ContainerStopped($containerName, $this->server, $url)); } $notRunningDatabases = $databases->pluck('id')->diff($foundDatabases); foreach ($notRunningDatabases as $database) { @@ -243,7 +239,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted } else { $url = null; } - $this->server->team->notify(new ContainerStopped($containerName, $this->server, $url)); + $this->server->team?->notify(new ContainerStopped($containerName, $this->server, $url)); } // Check if proxy is running @@ -256,7 +252,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted $shouldStart = CheckProxy::run($this->server); if ($shouldStart) { StartProxy::run($this->server, false); - $this->server->team->notify(new ContainerRestarted('coolify-proxy', $this->server)); + $this->server->team?->notify(new ContainerRestarted('coolify-proxy', $this->server)); } else { ray('Proxy could not be started.'); } @@ -272,7 +268,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted } catch (\Throwable $e) { send_internal_notification("ContainerStatusJob failed on ({$this->server->id}) with: " . $e->getMessage()); ray($e->getMessage()); - handleError($e); + return handleError($e); } } } diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 071c252ff..839f86835 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -281,7 +281,7 @@ function send_internal_notification(string $message): void try { $baseUrl = config('app.name'); $team = Team::find(0); - $team->notify(new GeneralNotification("👀 {$baseUrl}: " . $message)); + $team?->notify(new GeneralNotification("👀 {$baseUrl}: " . $message)); ray("👀 {$baseUrl}: " . $message); } catch (\Throwable $e) { ray($e->getMessage()); diff --git a/config/sentry.php b/config/sentry.php index efd043adf..c07fda49b 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.146', + 'release' => '4.0.0-beta.147', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 8c257643a..cf8ab7438 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@