소스 검색

优化合并 pdf 功能

yemeishu 15 시간 전
부모
커밋
fa4dcd07de
1개의 변경된 파일5개의 추가작업 그리고 6개의 파일을 삭제
  1. 5 6
      app/Jobs/GenerateExamPdfJob.php

+ 5 - 6
app/Jobs/GenerateExamPdfJob.php

@@ -20,7 +20,6 @@ class GenerateExamPdfJob implements ShouldQueue
 
     public string $taskId;
     public string $paperId;
-    public int $maxAttempts = 3;
 
     /**
      * 【优化】增加任务超时时间,给Chrome充足渲染时间
@@ -96,7 +95,7 @@ class GenerateExamPdfJob implements ShouldQueue
                 ]);
 
                 // 如果试卷不存在,判断是否需要重试
-                if ($this->attempts() < $this->maxAttempts) {
+                if ($this->attempts() < $this->tries) {
                     Log::info('试卷不存在,将在2秒后重试', [
                         'task_id' => $this->taskId,
                         'paper_id' => $this->paperId,
@@ -125,7 +124,7 @@ class GenerateExamPdfJob implements ShouldQueue
                     'question_count' => 0,
                 ]);
 
-                if ($this->attempts() < $this->maxAttempts) {
+                if ($this->attempts() < $this->tries) {
                     Log::info('试卷没有题目,将在1秒后重试', [
                         'task_id' => $this->taskId,
                         'paper_id' => $this->paperId,
@@ -170,7 +169,7 @@ class GenerateExamPdfJob implements ShouldQueue
                     'attempt' => $this->attempts(),
                 ]);
 
-                if ($this->attempts() < $this->maxAttempts) {
+                if ($this->attempts() < $this->tries) {
                     Log::info('合并PDF失败,将在3秒后重试', [
                         'task_id' => $this->taskId,
                         'paper_id' => $this->paperId,
@@ -231,14 +230,14 @@ class GenerateExamPdfJob implements ShouldQueue
                 'task_id' => $this->taskId,
                 'paper_id' => $this->paperId,
                 'attempt' => $this->attempts(),
-                'max_attempts' => $this->maxAttempts,
+                'max_attempts' => $this->tries,
                 'elapsed' => round($elapsed, 2) . 's',
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString(),
             ]);
 
             // 如果是第一次失败且试卷可能还在创建中,等待后重试
-            if ($this->attempts() < $this->maxAttempts && strpos($e->getMessage(), '不存在') !== false) {
+            if ($this->attempts() < $this->tries && strpos($e->getMessage(), '不存在') !== false) {
                 Log::info('检测到试卷不存在错误,将在2秒后重试', [
                     'task_id' => $this->taskId,
                     'paper_id' => $this->paperId,