1、app.__init__.py
from flask import Flask from flask_apscheduler import APScheduler import config
# 初始化app app = Flask(config.APP) app.config.from_object('config') # # 初始化定时任务模块 scheduler = APScheduler() scheduler.init_app(app) scheduler.start()
2、config.py
# 定时模块配置 from utils.scheduler_test import test, test2, test3 SCHEDULER_API_ENABLED = True SCHEDULER_JOBS = [ { 'id': 'test', 'func': test, 'args': '', 'trigger': { 'type': 'cron', 'day_of_week': "0-6", 'hour': '*', 'minute': '1', 'second': '0' } }, { 'id': 'test2', 'func': test2, 'args': '', 'trigger': 'interval', 'seconds': 5