CheckVideoGenerationTasksCommand.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\AIGeneration\AIVideoGenerationService;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\DB;
  6. class CheckVideoGenerationTasksCommand extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'AIGeneration:checkVideoTasks';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '检查视频生成任务状态并更新结果';
  20. /**
  21. * Execute the console command.
  22. *
  23. * @param AIVideoGenerationService $videoGenerationService
  24. * @return int
  25. */
  26. public function handle(AIVideoGenerationService $videoGenerationService)
  27. {
  28. dLog('generate')->info('开始检查视频生成任务状态...');
  29. // 执行50s
  30. $time_start = time();
  31. try {
  32. $count = DB::table('mp_generate_video_tasks')->where('status', 'processing')->count('id');
  33. while ($count > 0) {
  34. $time_diff = time() - $time_start;
  35. sleep(3);
  36. if ($time_diff > 50) break;
  37. $videoGenerationService->updatePendingTasks();
  38. $count = DB::table('mp_generate_video_tasks')->where('status', 'processing')->count('id');
  39. }
  40. dLog('generate')->info('视频任务状态检查完成');
  41. } catch (\Exception $e) {
  42. dLog('generate')->error('视频任务状态检查失败: ' . $e->getMessage());
  43. return 1;
  44. }
  45. return 0;
  46. }
  47. }