我按照其论坛方法配置flask-scheduler到sqlalchemy中,但是我重启任务或者添加任务并没有按照config文件配置到mysql当中,重启程序后无法重新加载上一次的任务
这个是config文件
SCHEDULER_API_ENABLED = True
SCHEDULER_JOBSTORES = {
'default': SQLAlchemyJobStore(url=DB_URL)
}
SCHEDULER_EXECUTORS = {
'default': {'type': 'threadpool', 'max_workers': 20}
}
SCHEDULER_JOB_DEFAULTS = {
'coalesce': False,
'max_instances': 3
}
这个是app.py
mport platform
from flask import Flask
from apps.cms import bp as cms_bp
from apps.fronts import bp as fronts_bp
from apps.common import bp as common_bp
from apps.equipment import bp as equipment_bp
from apps.file import bp as file_bp
from apps.muju import bp as muju_bp
from exts import *
from flask_wtf import CSRFProtect
import config
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
import atexit, fcntl, msvcrt, logging
from apps.common.models import Schedule
def create_app():
app = Flask(__name__)
app.config.from_object(config)
app.register_blueprint(cms_bp)
app.register_blueprint(fronts_bp)
app.register_blueprint(common_bp)
app.register_blueprint(equipment_bp)
app.register_blueprint(muju_bp)
app.register_blueprint(file_bp)
limiter = Limiter(app, key_func=get_remote_address, default_limits=["20000 per hour", "3000 per minute"])
limiter.init_app(app)
db.init_app(app)
scheduler_init(app)
mail.init_app(app)
CSRFProtect(app)
return app
def scheduler_init(app):
if platform.system() != 'Windows':
fcntl = __import__("fcntl")
f = open('scheduler.lock', 'wb')
try:
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
scheduler.init_app(app)
scheduler.start()
app.logger.debug('Scheduler Started,---------------')
except Exception as e:
print("scheduler init false!{}".format(e))
def unlock():
fcntl.flock(f, fcntl.LOCK_UN)
f.close()
atexit.register(unlock)
else:
msvcrt = __import__('msvcrt')
f = open('scheduler.lock', 'wb')
try:
msvcrt.locking(f.fileno(), msvcrt.LK_NBLCK, 1)
scheduler.init_app(app)
scheduler.start()
app.logger.debug('Scheduler Started,----------------')
except Exception as e:
print("scheduler init false!{}".format(e))
def _unlock_file():
try:
f.seek(0)
msvcrt.locking(f.fileno(), msvcrt.LK_UNLCK, 1)
except:
pass
atexit.register(_unlock_file)
logging.basicConfig(level=logging.DEBUG, # 控制台打印的日志级别
filename='flask2.log', # 将日志写入log_new.log文件中
filemode='a', ##模式,有w和a,w就是写模式,每次都会重新写日志,覆盖之前的日志
# a是追加模式,默认如果不写的话,就是追加模式
format=
'%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s'
# 日志格式
)
if __name__ == '__main__':
app = create_app()
app.run(host='0.0.0.0', threaded=True)