|
@@ -1,56 +1,33 @@
|
|
|
"""
|
|
|
@author: luojunhui
|
|
|
"""
|
|
|
-import time
|
|
|
-import threading
|
|
|
-from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
+from argparse import ArgumentParser
|
|
|
|
|
|
from coldStartTasks.publish import PublishVideosForAudit
|
|
|
-from applications.const import WeixinVideoCrawlerConst
|
|
|
|
|
|
-const = WeixinVideoCrawlerConst()
|
|
|
pub = PublishVideosForAudit()
|
|
|
|
|
|
|
|
|
-def run_thread(task_type: str, wait_time: int, stop_event: threading.Event):
|
|
|
- """
|
|
|
- 运行线程
|
|
|
- :param task_type:
|
|
|
- :param wait_time:
|
|
|
- :param stop_event:
|
|
|
- :return:
|
|
|
- """
|
|
|
-
|
|
|
- while not stop_event.is_set():
|
|
|
- if task_type == const.PUBLISH_TASK:
|
|
|
- # 发布视频
|
|
|
- pub.publish_job()
|
|
|
- time.sleep(wait_time)
|
|
|
- elif task_type == const.CHECK_TASK:
|
|
|
- # 检查视频
|
|
|
- pub.check_job()
|
|
|
- time.sleep(wait_time)
|
|
|
-
|
|
|
-
|
|
|
def main():
|
|
|
"""
|
|
|
主函数
|
|
|
:return:
|
|
|
"""
|
|
|
- stop_event = threading.Event()
|
|
|
+ parser = ArgumentParser()
|
|
|
+ parser.add_argument("--run_task", type=str, help="run task, input publish or check")
|
|
|
+ args = parser.parse_args()
|
|
|
|
|
|
- # 启动两个线程,分别执行两个函数
|
|
|
- with ThreadPoolExecutor(max_workers=2) as executor:
|
|
|
- futures = [
|
|
|
- executor.submit(run_thread, const.PUBLISH_TASK, const.PUBLISH_TASK_SLEEP_TEME, stop_event),
|
|
|
- executor.submit(run_thread, const.CHECK_TASK, const.CHECK_TASK_SLEEP_TEME, stop_event)
|
|
|
- ]
|
|
|
- try:
|
|
|
- for future in as_completed(futures):
|
|
|
- future.result()
|
|
|
- except KeyboardInterrupt:
|
|
|
- print("Stopping all threads...")
|
|
|
- stop_event.set()
|
|
|
+ if args.run_task:
|
|
|
+ task = args.run_task
|
|
|
+ if task == "publish":
|
|
|
+ pub.publish_job()
|
|
|
+ elif task == "check":
|
|
|
+ pub.check_job()
|
|
|
+ else:
|
|
|
+ print("run_task input ERROR,please input publish or check")
|
|
|
+ else:
|
|
|
+ pub.publish_job()
|
|
|
+ pub.check_job()
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|