From 71d120bc4e4bac6881443777a49bcd38aec901c3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 30 May 2024 12:56:29 +0200 Subject: [PATCH] fix: fine-tune cdn pulls --- app/Console/Kernel.php | 8 +++- ...dVersions.php => PullTemplatesFromCDN.php} | 17 +------- app/Jobs/PullVersionsFromCDN.php | 41 +++++++++++++++++++ 3 files changed, 48 insertions(+), 18 deletions(-) rename app/Jobs/{PullTemplatesAndVersions.php => PullTemplatesFromCDN.php} (60%) create mode 100644 app/Jobs/PullVersionsFromCDN.php diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 2c49a3096..ab8794877 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -11,6 +11,8 @@ use App\Jobs\PullHelperImageJob; use App\Jobs\PullSentinelImageJob; use App\Jobs\PullTemplatesAndVersions; +use App\Jobs\PullTemplatesFromCDN; +use App\Jobs\PullVersionsFromCDN; use App\Jobs\ServerStatusJob; use App\Models\InstanceSettings; use App\Models\ScheduledDatabaseBackup; @@ -30,7 +32,8 @@ protected function schedule(Schedule $schedule): void // Instance Jobs $schedule->command('horizon:snapshot')->everyMinute(); $schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer(); - $schedule->job(new PullTemplatesAndVersions)->everyTenMinutes()->onOneServer(); + $schedule->job(new PullVersionsFromCDN)->everyTenMinutes()->onOneServer(); + $schedule->job(new PullTemplatesFromCDN)->everyTwoHours()->onOneServer(); // $schedule->job(new CheckResaleLicenseJob)->hourly()->onOneServer(); // Server Jobs $this->check_scheduled_backups($schedule); @@ -43,7 +46,8 @@ protected function schedule(Schedule $schedule): void // Instance Jobs $schedule->command('horizon:snapshot')->everyFiveMinutes(); $schedule->command('cleanup:unreachable-servers')->daily(); - $schedule->job(new PullTemplatesAndVersions)->everyTenMinutes()->onOneServer(); + $schedule->job(new PullVersionsFromCDN)->everyTenMinutes()->onOneServer(); + $schedule->job(new PullTemplatesFromCDN)->everyTwoHours()->onOneServer(); $schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer(); // $schedule->job(new CheckResaleLicenseJob)->hourly()->onOneServer(); diff --git a/app/Jobs/PullTemplatesAndVersions.php b/app/Jobs/PullTemplatesFromCDN.php similarity index 60% rename from app/Jobs/PullTemplatesAndVersions.php rename to app/Jobs/PullTemplatesFromCDN.php index c4c2619ca..66e7611a7 100644 --- a/app/Jobs/PullTemplatesAndVersions.php +++ b/app/Jobs/PullTemplatesFromCDN.php @@ -12,7 +12,7 @@ use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Http; -class PullTemplatesAndVersions implements ShouldQueue, ShouldBeEncrypted +class PullTemplatesFromCDN implements ShouldQueue, ShouldBeEncrypted { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; @@ -23,21 +23,6 @@ public function __construct() } public function handle(): void { - try { - if (!isDev() && !isCloud()) { - ray('PullTemplatesAndVersions versions.json'); - $response = Http::retry(3, 1000)->get('https://cdn.coollabs.io/coolify/versions.json'); - if ($response->successful()) { - $versions = $response->json(); - File::put(base_path('versions.json'), json_encode($versions, JSON_PRETTY_PRINT)); - } else { - send_internal_notification('PullTemplatesAndVersions failed with: ' . $response->status() . ' ' . $response->body()); - } - } - } catch (\Throwable $e) { - send_internal_notification('PullTemplatesAndVersions failed with: ' . $e->getMessage()); - ray($e->getMessage()); - } try { if (!isDev()) { ray('PullTemplatesAndVersions service-templates'); diff --git a/app/Jobs/PullVersionsFromCDN.php b/app/Jobs/PullVersionsFromCDN.php new file mode 100644 index 000000000..0d4084a30 --- /dev/null +++ b/app/Jobs/PullVersionsFromCDN.php @@ -0,0 +1,41 @@ +get('https://cdn.coollabs.io/coolify/versions.json'); + if ($response->successful()) { + $versions = $response->json(); + File::put(base_path('versions.json'), json_encode($versions, JSON_PRETTY_PRINT)); + } else { + send_internal_notification('PullTemplatesAndVersions failed with: ' . $response->status() . ' ' . $response->body()); + } + } + } catch (\Throwable $e) { + send_internal_notification('PullTemplatesAndVersions failed with: ' . $e->getMessage()); + ray($e->getMessage()); + } + } +}