|
@@ -62,21 +62,14 @@ def train_and_save_model():
|
|
|
joblib.dump(model, model_save_path)
|
|
|
print(f"✅ 模型训练完成,已保存为 {model_save_path}")
|
|
|
|
|
|
- # 设置定时任务调度器
|
|
|
- scheduler = BlockingScheduler()
|
|
|
+# === 启动定时任务调度器 ===
|
|
|
+if __name__ == '__main__':
|
|
|
+ # 先执行一次
|
|
|
+ train_and_save_model()
|
|
|
|
|
|
- # 每小时执行一次 train_and_save_model 函数
|
|
|
+ # 然后设置每小时定时执行
|
|
|
+ scheduler = BlockingScheduler()
|
|
|
scheduler.add_job(train_and_save_model, 'interval', hours=1)
|
|
|
+ print("⏰ 启动定时任务调度器:每小时自动训练模型...")
|
|
|
+ scheduler.start()
|
|
|
|
|
|
- # 启动定时任务调度器
|
|
|
- print("⏰ 启动定时任务调度器,每小时自动训练模型...")
|
|
|
-
|
|
|
-# 设置定时任务调度器
|
|
|
-scheduler = BlockingScheduler()
|
|
|
-
|
|
|
-# 每小时执行一次 train_and_save_model 函数
|
|
|
-scheduler.add_job(train_and_save_model, 'interval', hours=1)
|
|
|
-
|
|
|
-# 启动定时任务调度器
|
|
|
-print("⏰ 启动定时任务调度器,每小时自动训练模型...")
|
|
|
-scheduler.start()
|