Ver Fonte

调整定时任务兼容gpt

lh há 2 meses atrás
pai
commit
0433b8b9f5

+ 14 - 4
app/Console/Commands/CheckImageGenerationTasksCommand.php

@@ -36,7 +36,7 @@ class CheckImageGenerationTasksCommand extends Command
         // 执行50s
         $time_start = time();
         try {
-            // 统计需要处理的任务数量(即梦AI的processing + 火山API的pending和processing)
+            // 统计需要处理的任务数量(即梦AI的processing + 火山API和GPT的pending和processing)
             $jimengProcessingCount = DB::table('mp_generate_pic_tasks')
                 ->where('status', 'processing')
                 ->where('model', 'jimeng_4.0')
@@ -47,9 +47,14 @@ class CheckImageGenerationTasksCommand extends Command
                 ->whereIn('model', BaseConst::VOLC_PIC_MODELS)
                 ->count('id');
             
-            $totalCount = $jimengProcessingCount + $volcPendingCount;
+            $gptPendingCount = DB::table('mp_generate_pic_tasks')
+                ->where('status', 'pending')
+                ->whereIn('model', BaseConst::GPT_IMAGE2_MODELS)
+                ->count('id');
+            
+            $totalCount = $jimengProcessingCount + $volcPendingCount + $gptPendingCount;
             
-            dLog('command')->info("待处理任务统计 - 即梦AI处理中: {$jimengProcessingCount}, 火山API待处理: {$volcPendingCount}");
+            dLog('command')->info("待处理任务统计 - 即梦AI处理中: {$jimengProcessingCount}, 火山API待处理: {$volcPendingCount}, GPT待处理: {$gptPendingCount}");
             
             while ($totalCount > 0) {
                 $time_diff = time() - $time_start;
@@ -74,7 +79,12 @@ class CheckImageGenerationTasksCommand extends Command
                     ->whereIn('model', BaseConst::VOLC_PIC_MODELS)
                     ->count('id');
                 
-                $totalCount = $jimengProcessingCount + $volcPendingCount;
+                $gptPendingCount = DB::table('mp_generate_pic_tasks')
+                    ->where('status', 'pending')
+                    ->whereIn('model', BaseConst::GPT_IMAGE2_MODELS)
+                    ->count('id');
+                
+                $totalCount = $jimengProcessingCount + $volcPendingCount + $gptPendingCount;
             }
             
             dLog('command')->info('任务状态检查完成');

+ 9 - 5
app/Services/Anime/AnimeService.php

@@ -2846,9 +2846,11 @@ class AnimeService
             return '';
         }
 
-        // 检查任务模型类型
+        // 检查任务模型类型(火山模型和GPT模型都支持直接检查任务状态)
         $model = getProp($task, 'model');
         $isVolcModel = in_array($model, \App\Consts\BaseConst::VOLC_PIC_MODELS);
+        $isGptModel = in_array($model, \App\Consts\BaseConst::GPT_IMAGE2_MODELS);
+        $isSyncModel = $isVolcModel || $isGptModel;
 
         // 轮询查询任务状态(火山API和即梦AI都需要轮询)
         $start_count = 0;
@@ -2869,7 +2871,7 @@ class AnimeService
                 return '';
             }
 
-            if ($isVolcModel) continue;
+            if ($isSyncModel) continue;
             
             // 查询任务状态
             $statusInfo = $this->aiImageGenerationService->queryTaskStatus($task);
@@ -3807,9 +3809,11 @@ class AnimeService
                 Utils::throwError('20003:创建图片生成任务失败');
             }
             
-            // 检查任务模型类型
+            // 检查任务模型类型(火山模型和GPT模型都支持直接检查任务状态)
             $model = getProp($task, 'model');
             $isVolcModel = in_array($model, \App\Consts\BaseConst::VOLC_PIC_MODELS);
+            $isGptModel = in_array($model, \App\Consts\BaseConst::GPT_IMAGE2_MODELS);
+            $isSyncModel = $isVolcModel || $isGptModel;
 
             // 即梦AI需要轮询获取结果(3分钟超时,每3秒查询一次)
             $start_time = time();
@@ -3819,8 +3823,8 @@ class AnimeService
             while (time() - $start_time < $timeout) {
                 sleep(3);
 
-                // 火山API是同步返回结果的,直接检查任务状态
-                if ($isVolcModel) {
+                // 火山API和GPT-Image2 API是同步返回结果的,直接检查任务状态
+                if ($isSyncModel) {
                     // 刷新任务状态
                     $task = MpGeneratePicTask::where('id', $task_id)->first();