123456789101112131415161718192021222324252627282930313233343536 |
- import time
- from concurrent.futures import ThreadPoolExecutor, wait
- from common.redis import install_video_data
- from video_processing.video_processing import VideoProcessing
- max_workers = 6
- def video_ai_task_start():
- with ThreadPoolExecutor( max_workers=max_workers) as executor:
- while True:
- redis_task_list = ['task:video_ai_top', 'task:video_ai_recommend']
- try:
- 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(1)
- continue
- def process_video_ai(redis_task):
- try:
- print(f"开始执行任务{redis_task}")
- video_processor = VideoProcessing()
- video_processor.get_video(redis_task)
- print(f"执行完成{redis_task}")
- time.sleep(5)
- except Exception as e:
- print("处理任务时出现异常:", e)
- time.sleep(5)
- if __name__ == '__main__':
- video_ai_task_start()
|