agc_gs_main.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import os
  2. import concurrent.futures
  3. import schedule
  4. import time
  5. import threading
  6. from common import Material
  7. from video_agc.agc_video import AGC
  8. # 控制读写速度的参数
  9. MAX_BPS = 1 * 1024 * 1024 # 120MB/s
  10. MAX_WORKERS = os.cpu_count() * 5 # 线程池最大工作线程数量
  11. READ_WRITE_CHUNK_SIZE = 512 * 1024 # 每次读写的块大小 (1MB)
  12. SLEEP_INTERVAL = READ_WRITE_CHUNK_SIZE / MAX_BPS # 控制每次读写的延迟时间
  13. # 全局锁,用于同步读写操作
  14. lock = threading.Lock()
  15. def controlled_io_operation(platform, data):
  16. with lock:
  17. start_time = time.time()
  18. time.sleep(SLEEP_INTERVAL)
  19. end_time = time.time()
  20. elapsed_time = end_time - start_time
  21. if elapsed_time < SLEEP_INTERVAL:
  22. time.sleep(SLEEP_INTERVAL - elapsed_time)
  23. if platform == "gs":
  24. AGC.video(data, "跟随")
  25. elif platform == "cg":
  26. AGC.video(data, "常规")
  27. elif platform == "bk":
  28. AGC.video(data, "爆款")
  29. def video_start(platform):
  30. print("开始执行生成视频脚本.")
  31. if platform == "cg":
  32. data = Material.feishu_list()
  33. elif platform == "gs":
  34. data = Material.feishu_gs_list()
  35. elif platform == "bk":
  36. data = Material.feishu_bk_list()
  37. with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
  38. futures = {executor.submit(controlled_io_operation, platform, user_data): user_data for user_data in data}
  39. for future in concurrent.futures.as_completed(futures):
  40. try:
  41. future.result()
  42. print("处理结果: 成功")
  43. except concurrent.futures.TimeoutError:
  44. print("任务超时,已取消.")
  45. except Exception as e:
  46. print("处理任务时出现异常:", e)
  47. print("执行生成视频脚本结束.")
  48. schedule.every().day.at("19:40").do(video_start, "gs")
  49. if __name__ == "__main__":
  50. # video_start("cg")
  51. while True:
  52. try:
  53. schedule.run_pending()
  54. except Exception as e:
  55. print("执行调度任务时出现异常:", e)
  56. time.sleep(1)