paperId = $paperId; $this->studentId = $studentId; $this->recordId = $recordId; } 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) { Log::info('学情分析PDF生成成功', [ 'paper_id' => $this->paperId, 'student_id' => $this->studentId, 'record_id' => $this->recordId, 'pdf_url' => $pdfUrl, ]); } else { Log::error('学情分析PDF生成失败', [ 'paper_id' => $this->paperId, 'student_id' => $this->studentId, 'record_id' => $this->recordId, ]); // 如果失败且还有重试次数,则重试 if ($this->attempts() < $this->maxAttempts) { Log::info('将在5秒后重试PDF生成', [ 'paper_id' => $this->paperId, 'student_id' => $this->studentId, 'attempt' => $this->attempts(), ]); $this->release(5); return; } } } catch (\Exception $e) { Log::error('学情分析PDF生成队列任务失败', [ 'paper_id' => $this->paperId, 'student_id' => $this->studentId, 'record_id' => $this->recordId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString(), ]); // 如果是第一次失败且可能是临时错误,等待后重试 if ($this->attempts() < $this->maxAttempts) { Log::info('检测到临时错误,将在10秒后重试', [ 'paper_id' => $this->paperId, 'student_id' => $this->studentId, 'attempt' => $this->attempts(), ]); $this->release(10); return; } } } }