| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Console\Commands;
- use App\Services\AIGeneration\AIVideoGenerationService;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- class CheckVideoGenerationTasksCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'AIGeneration:checkVideoTasks';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '检查视频生成任务状态并更新结果';
- /**
- * Execute the console command.
- *
- * @param AIVideoGenerationService $videoGenerationService
- * @return int
- */
- public function handle(AIVideoGenerationService $videoGenerationService)
- {
- dLog('generate')->info('开始检查视频生成任务状态...');
- // 执行50s
- $time_start = time();
- try {
- $count = DB::table('mp_generate_video_tasks')->where('status', 'processing')->count('id');
- while ($count > 0) {
- $time_diff = time() - $time_start;
- sleep(3);
- if ($time_diff > 50) break;
- $videoGenerationService->updatePendingTasks();
- $count = DB::table('mp_generate_video_tasks')->where('status', 'processing')->count('id');
- }
- dLog('generate')->info('视频任务状态检查完成');
- } catch (\Exception $e) {
- dLog('generate')->error('视频任务状态检查失败: ' . $e->getMessage());
- return 1;
- }
- return 0;
- }
- }
|