zhangyong 8 mēneši atpakaļ
vecāks
revīzija
34c3fc2496
3 mainītis faili ar 13 papildinājumiem un 9 dzēšanām
  1. 8 6
      common/redis.py
  2. 1 1
      job_dd_sph.py
  3. 4 2
      video_rewriting/video_processor.py

+ 8 - 6
common/redis.py

@@ -1,5 +1,4 @@
 import redis
-from datetime import timedelta
 
 
 class SyncRedisHelper:
@@ -47,8 +46,11 @@ def get_data(name, data):
         client.rpush(task, *data)
     return client.lpop(task)
 
-# value = get_data('xiaoniangao', '1234857')
-# if value is None:
-#     print("Value does not exist")
-# else:
-#     print(f"Retrieved value: {value}")
+def get_redis_video_data(video_id):
+    lock = f"video_lock:{video_id}"
+    helper = SyncRedisHelper()
+    client = helper.get_client()
+    acquire_lock = client.set(lock, 1, ex=600, nx=True)
+    if not acquire_lock:
+        return True
+    return False

+ 1 - 1
job_dd_sph.py

@@ -11,7 +11,7 @@ def video_task_start():
             print("开始执行任务")
             mark = VideoProcessor.main(data)
             print(f"返回用户名: {mark}")
-            time.sleep(360 if mark else 3600)  # 根据 mark 是否为空设置延迟
+            time.sleep(360 if mark else 360)  # 根据 mark 是否为空设置延迟
         except Exception as e:
             print("处理任务时出现异常:", e)
             time.sleep(10)

+ 4 - 2
video_rewriting/video_processor.py

@@ -9,7 +9,7 @@ import time
 from datetime import datetime
 import concurrent.futures
 
-from common.redis import get_data
+from common.redis import get_data, get_redis_video_data
 from common.tts_help import TTS
 from common import Material, Feishu, Common, Oss
 from common.ffmpeg import FFmpeg
@@ -109,7 +109,9 @@ class VideoProcessor:
                 video_url = video["video_url"]
                 old_title = video['old_title']
                 rule = video['rule']
-
+                redis_video = get_redis_video_data(v_id)
+                if redis_video:
+                    continue
                 if not old_title:
                     old_title = '这个视频,分享给我的老友,祝愿您能幸福安康'
                     text = (