onQueue((string) config('queue.workloads.pdf', 'pdf')); // 避免事务未提交时 worker 提前消费导致读到旧数据 $this->afterCommit(); } public function handle(ExamAnalysisService $examAnalysisService): void { try { Log::info('ProcessAnalysisReportTaskJob: 开始处理学情报告任务', [ 'task_id' => $this->taskId, 'paper_id' => $this->paperId, 'student_id' => $this->studentId, 'record_id' => $this->recordId, 'attempt' => $this->attempts(), ]); $examAnalysisService->processReportGenerationTask( $this->taskId, $this->paperId, $this->studentId, $this->recordId ); } catch (Throwable $e) { Log::error('ProcessAnalysisReportTaskJob: 处理失败,将交由队列重试/失败落库', [ 'task_id' => $this->taskId, 'paper_id' => $this->paperId, 'student_id' => $this->studentId, 'record_id' => $this->recordId, 'attempt' => $this->attempts(), 'error' => $e->getMessage(), ]); throw $e; } } public function failed(Throwable $exception): void { try { $taskManager = app(TaskManager::class); $taskManager->markTaskFailed( $this->taskId, '学情报告生成失败:'.$exception->getMessage() ); // 与成功路径保持一致:最终失败也发回调,避免调用方只等待回调而无结果。 $taskManager->sendCallback($this->taskId); } catch (Throwable $innerException) { Log::error('ProcessAnalysisReportTaskJob: failed回调更新任务失败', [ 'task_id' => $this->taskId, 'error' => $innerException->getMessage(), ]); } Log::error('ProcessAnalysisReportTaskJob: 队列任务最终失败', [ 'task_id' => $this->taskId, 'paper_id' => $this->paperId, 'student_id' => $this->studentId, 'record_id' => $this->recordId, 'error' => $exception->getMessage(), ]); } }