onQueue(isCloud() ? maintenance_queue() : 'default'); } public function uniqueId(): string { return (string) $this->server->id; } public static function runningCacheKey(Server $server): string { return "server-host-scan-running:{$server->id}"; } /** * Queues a scan and marks it as running, so the patches page shows the progress after a reload. The mark lasts * for the longest wait in the queue and the longest run. Each request writes a new token, so a scan that started * before this request cannot clear the marker of this request. */ public static function dispatchManual(Server $server): void { Cache::put(self::runningCacheKey($server), (string) Str::uuid(), now()->addSeconds(2 * ScanImage::lockTtl($server))); self::dispatch($server); } public function handle(): void { $server = $this->server->fresh(['settings']); if (! $server instanceof Server) { return; } $request = Cache::get(self::runningCacheKey($server)); if (! ScanHostPackages::run($server)) { if ($this->attempts() < $this->tries) { $this->release(self::RETRY_DELAY_SECONDS); return; } ScanHostPackages::recordFailure($server, ImageScanErrorCode::LockBusy); } // A request made during this scan queued a new scan, which clears the marker when it ends. if (Cache::get(self::runningCacheKey($server)) === $request) { Cache::forget(self::runningCacheKey($server)); } ServerPatchCheckFinished::dispatch($server->team_id, $server->uuid); } public function failed(): void { Cache::forget(self::runningCacheKey($this->server)); } }