lh hai 2 días
pai
achega
8be69f3544
Modificáronse 1 ficheiros con 26 adicións e 1 borrados
  1. 26 1
      app/Console/Commands/ProcessBatchEpisodeGenerationCommand.php

+ 26 - 1
app/Console/Commands/ProcessBatchEpisodeGenerationCommand.php

@@ -25,7 +25,7 @@ class ProcessBatchEpisodeGenerationCommand extends Command
      *
      * @var string
      */
-    protected $description = '批量生成分集定时任务,每次处理一个待生成的剧集';
+    protected $description = '批量生成分集定时任务,每5秒检查一次待处理任务,单次最多执行50秒';
 
     protected $deepSeekService;
 
@@ -49,6 +49,29 @@ class ProcessBatchEpisodeGenerationCommand extends Command
     {
         dLog('command')->info('开始执行批量生成分集任务...');
 
+        // 每5秒执行一次任务,直到50秒后停止(参考 CheckVideoGenerationTasksCommand 的循环逻辑)
+        $time_start = time();
+        while (true) {
+            $time_diff = time() - $time_start;
+            sleep(5);
+            if ($time_diff > 50) {
+                break;
+            }
+
+            // 处理一个待生成的剧集;返回 1 表示处理失败,结束本次执行
+            $result = $this->processPendingEpisodeTask();
+        }
+
+        return 0;
+    }
+
+    /**
+     * 处理一个待生成的剧集
+     *
+     * @return int 0-成功或无任务可处理(可继续下一轮),1-处理失败
+     */
+    private function processPendingEpisodeTask()
+    {
         $anime_tasks = DB::table('mp_batch_episode_generation_details')->where('status', 'pending')->pluck('anime_id')->toArray();
         foreach ($anime_tasks as $anime_id) {
             dLog('command')->info("~~~~~~开始执行($anime_id)任务~~~~~~");
@@ -223,5 +246,7 @@ class ProcessBatchEpisodeGenerationCommand extends Command
                 return 1;
             }
         }
+
+        return 0;
     }
 }