jobUuid = $jobUuid; } public function handle(): void { $job = CrawlShotJob::where('uuid', $this->jobUuid)->first(); if (!$job) { Log::error("CrawlShotJob not found: {$this->jobUuid}"); return; } try { $job->update([ 'status' => 'processing', 'started_at' => now() ]); $browsershot = new BrowsershotService(); if ($job->type === 'crawl') { $result = $browsershot->crawlHtml($job->url, $job->parameters ?? []); $this->saveCrawlResult($job, $result); } elseif ($job->type === 'shot') { $result = $browsershot->takeScreenshot($job->url, $job->parameters ?? []); $this->saveScreenshotResult($job, $result); } $job->update([ 'status' => 'completed', 'completed_at' => now() ]); } catch (\Exception $e) { Log::error("Job {$this->jobUuid} failed: " . $e->getMessage()); $job->update([ 'status' => 'failed', 'error_message' => $e->getMessage(), 'completed_at' => now() ]); } } private function saveCrawlResult(CrawlShotJob $job, string $html): void { $filename = "{$job->uuid}.html"; $path = "crawlshot/html/{$filename}"; Storage::put($path, $html); $job->update(['file_path' => $path]); } private function saveScreenshotResult(CrawlShotJob $job, array $result): void { $parameters = $job->parameters ?? []; $format = $parameters['format'] ?? 'jpg'; $filename = "{$job->uuid}.{$format}"; $path = "crawlshot/images/{$filename}"; Storage::put($path, $result['data']); $job->update(['file_path' => $path]); } }