paperId = $paperId; $this->studentId = $studentId; $this->recordId = $recordId; // 指定使用 pdf 队列,由独立的 pdf-worker 容器处理 $this->onQueue((string) config('queue.workloads.pdf', 'pdf')); // 避免事务未提交时 worker 提前消费导致读到未提交数据 $this->afterCommit(); } public function handle(ExamPdfExportService $pdfExportService): void { try { Log::info('开始处理学情分析PDF生成队列任务', [ 'paper_id' => $this->paperId, 'student_id' => $this->studentId, 'record_id' => $this->recordId, 'attempt' => $this->attempts(), ]); // 生成学情分析PDF $pdfUrl = $pdfExportService->generateAnalysisReportPdf( $this->paperId, $this->studentId, $this->recordId ); if (! $pdfUrl) { throw new \RuntimeException('学情分析PDF生成失败:返回空URL'); } Log::info('学情分析PDF生成成功', [ 'paper_id' => $this->paperId, 'student_id' => $this->studentId, 'record_id' => $this->recordId, 'pdf_url' => $pdfUrl, ]); } catch (\Throwable $e) { Log::error('学情分析PDF生成队列任务失败', [ 'paper_id' => $this->paperId, 'student_id' => $this->studentId, 'record_id' => $this->recordId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString(), 'attempt' => $this->attempts(), ]); throw $e; } } public function failed(Throwable $exception): void { Log::error('学情分析PDF生成队列任务最终失败', [ 'paper_id' => $this->paperId, 'student_id' => $this->studentId, 'record_id' => $this->recordId, 'error' => $exception->getMessage(), ]); } }