import asyncio import threading from concurrent.futures import ThreadPoolExecutor from batch_task.update_llm_intent import update_llm_intent from common.log import log batch_task_event = threading.Event() async def periodically_execute(interval, func, *args, **kwargs): while True: await func(*args, **kwargs) await asyncio.sleep(interval) async def execute_task(): batch_task_event.set() while batch_task_event.is_set(): await update_llm_intent() log.info("Task executed. Sleeping for 10 seconds...") await asyncio.sleep(10) def start_batch_task(): global batch_task_event if not batch_task_event.is_set(): log.info("Starting task.") batch_task_event.set() asyncio.run(execute_task()) # asyncio.create_task(execute_task()) def stop_batch_task(): global batch_task_event # 清除事件 batch_task_event.clear() log.info("Stop task.")