| 
					
				 | 
			
			
				@@ -1,41 +1,24 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import time 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+from concurrent.futures import ThreadPoolExecutor, wait 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+from common.redis import install_video_data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 from video_processing.video_processing import VideoProcessing 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-from concurrent.futures import ThreadPoolExecutor, wait, as_completed 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 max_workers = 6 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def video_ai_task_start(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    redis_task_list = ['task:video_ai_top', 'task:video_ai_recommend'] * 3  # 模拟任务列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    with ThreadPoolExecutor( max_workers=max_workers ) as executor: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        futures = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        task_index = 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        total_tasks = len( redis_task_list ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    with ThreadPoolExecutor( max_workers=max_workers) as executor: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         while True: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redis_task_list = ['task:video_ai_top', 'task:video_ai_recommend'] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             try: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                while len( futures ) < max_workers and task_index < total_tasks: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    redis_task = redis_task_list[task_index] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    futures.append( executor.submit( process_video_ai, redis_task ) ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    print( f"提交任务: {redis_task}" ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    task_index += 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    time.sleep( 1 ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                for future in as_completed( futures ): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    futures.remove( future ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    print( f"完成一个任务,当前运行中的任务数:{len( futures )}" ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if task_index < total_tasks: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        redis_task = redis_task_list[task_index] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        futures.append( executor.submit( process_video_ai, redis_task ) ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        print( f"补充新任务: {redis_task}" ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        task_index += 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        time.sleep( 1 ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                futures = [] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                for redis_task in redis_task_list: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    futures.append(executor.submit( process_video_ai, redis_task)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    time.sleep(1)  # 每秒提交一个任务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                wait( futures )  # 等待所有任务完成 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             except Exception as e: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                print( f"异常信息: {e}" ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                time.sleep( 3 ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                print(f"异常信息{e}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                time.sleep(1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 continue 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 def process_video_ai(redis_task): 
			 |