import sys import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.join(BASE_DIR)) sys.path.insert(0, os.path.join(BASE_DIR, 'reco_sys')) from apscheduler.schedulers.blocking import BlockingScheduler from apscheduler.executors.pool import ProcessPoolExecutor from scheduler.update import update_article_profile, update_user_profile, update_user_recal, update_feature import setting.logging as lg # 初始化自定义日志打印的位置和名称 lg.create_logger() # 创建scheduler,多进程执行 executors = { 'default': ProcessPoolExecutor(3) } scheduler = BlockingScheduler(executors=executors) # 添加一个文章画像更新任务,每个一个小时运行一次更新 scheduler.add_job(update_article_profile, trigger='interval', hours=1) # 添加一个定时的用户画像的更新任务,每隔2个小时更新一次用户画像 scheduler.add_job(update_user_profile, trigger='interval', hours=2) # 添加一个定时运行用户召回结果的任务, 每隔3小时新推荐一次用户的召回池 scheduler.add_job(update_user_recal, trigger='interval', hours=3) # 添加一个定时运行特征中心的更新任务, 每隔4小时新推荐一次用户的召回池 scheduler.add_job(update_feature, trigger='interval', hours=4) # 启动 scheduler.start()