Files
coolify/app/Jobs/CheckForUpdatesJob.php
T
Andras BacsaiandClaude Opus 5.5 dbc3fb91bf fix(cdn): fetch versions.json once per hour, spread evenly across instances
- Retry CDN requests only for transient errors and honor Retry-After
  (Cloudflare error 1200 sends 60 s), with jitter.
- Read helper and Sentinel versions from the local versions.json, which
  the hourly update check refreshes, instead of fetching per job/server.
- Replace the random 0-600 s delay with a stable per-instance offset
  inside the cron interval (max 1 h).
- Manual update checks and upgrades make one CDN attempt only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 18:10:48 +02:00

45 lines
1.3 KiB
PHP

<?php
namespace App\Jobs;
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\SerializesModels;
class CheckForUpdatesJob implements ShouldBeEncrypted, ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/** A manual check runs in the web request, so it does not wait for CDN retries. */
public int $cdnTries = 3;
public function __construct(int $cdnTries = 3)
{
$this->cdnTries = $cdnTries;
}
public function handle(): void
{
try {
if (isDev() || isCloud()) {
return;
}
$versions = refresh_versions_file($this->cdnTries);
if ($versions === null) {
return;
}
CheckTraefikVersionJob::dispatch();
$latestVersion = data_get($versions, 'coolify.v4.version');
$newVersionAvailable = version_compare($latestVersion, config('constants.coolify.version'), '>');
instanceSettings()->update(['new_version_available' => $newVersionAvailable]);
} catch (\Throwable $e) {
// Consider implementing a notification to administrators
}
}
}