onQueue(config('cdn.pipeline.queue', 'cdn')); } /** * Execute the job. * * @param object|null $storage StorageManager instance when Plug module available */ public function handle(?object $storage = null): void { if (! class_exists(StorageManager::class)) { Log::warning('PushAssetToCdn: StorageManager not available, Plug module not installed'); return; } // Resolve from container if not injected if ($storage === null) { $storage = app(StorageManager::class); } if (! config('cdn.bunny.push_enabled', false)) { Log::debug('PushAssetToCdn: Push disabled, skipping', [ 'disk' => $this->disk, 'path' => $this->path, ]); return; } $uploader = $storage->zone($this->zone)->upload(); if (! $uploader->isConfigured()) { Log::warning('PushAssetToCdn: CDN storage not configured', [ 'zone' => $this->zone, ]); return; } // Get contents from origin disk $sourceDisk = Storage::disk($this->disk); if (! $sourceDisk->exists($this->path)) { Log::warning('PushAssetToCdn: Source file not found on disk', [ 'disk' => $this->disk, 'path' => $this->path, ]); return; } $contents = $sourceDisk->get($this->path); $result = $uploader->contents($this->path, $contents); if ($result->hasError()) { Log::error('PushAssetToCdn: Failed to push asset', [ 'disk' => $this->disk, 'path' => $this->path, 'zone' => $this->zone, 'error' => $result->message(), ]); $this->fail(new \Exception("Failed to push {$this->path} to CDN zone {$this->zone}")); } Log::info('PushAssetToCdn: Asset pushed successfully', [ 'disk' => $this->disk, 'path' => $this->path, 'zone' => $this->zone, ]); } /** * Get the tags that should be assigned to the job. * * @return array */ public function tags(): array { return [ 'cdn', 'push', "zone:{$this->zone}", "path:{$this->path}", ]; } /** * Determine if the job should be unique. */ public function uniqueId(): string { return "{$this->zone}:{$this->path}"; } /** * The unique ID of the job. */ public function uniqueFor(): int { return 300; // 5 minutes } }