job_pl_dy_1.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import os
  2. import concurrent.futures
  3. import schedule
  4. import time
  5. import threading
  6. from common import Material
  7. from video_rewriting.video_processor import VideoProcessor
  8. MAX_BPS = 120 * 1024 * 1024 # 120MB/s
  9. MAX_WORKERS = os.cpu_count() * 2 # 线程池最大工作线程数量
  10. READ_WRITE_CHUNK_SIZE = 1024 * 1024 # 每次读写的块大小 (1MB)
  11. SLEEP_INTERVAL = READ_WRITE_CHUNK_SIZE / MAX_BPS # 控制每次读写的延迟时间
  12. # 全局锁,用于同步读写操作
  13. lock = threading.Lock()
  14. def video_task_start(data):
  15. mark = VideoProcessor.main(data)
  16. print(f"返回用户名{mark}")
  17. data = Material.feishu_list()
  18. video_task_start(data[5])
  19. # def controlled_io_operation(data):
  20. # with lock:
  21. # start_time = time.time()
  22. # time.sleep(SLEEP_INTERVAL)
  23. # end_time = time.time()
  24. # elapsed_time = end_time - start_time
  25. # if elapsed_time < SLEEP_INTERVAL:
  26. # time.sleep(SLEEP_INTERVAL - elapsed_time)
  27. # video_task_start(data)
  28. #
  29. #
  30. #
  31. #
  32. # def video_start():
  33. # print("开始执行生成视频脚本.")
  34. #
  35. # data = Material.feishu_list()
  36. # data = data[5]
  37. # with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
  38. # futures = {executor.submit(controlled_io_operation, 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. #
  49. #
  50. # video_start()
  51. # schedule.every(6).hours.do(video_start)
  52. # while True:
  53. # schedule.run_pending()
  54. # time.sleep(1)