#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ # @Version : Python 3.11.4 # @Software : Sublime Text 4 # @Author : StudentCWZ # @Email : StudentCWZ@outlook.com # @Date : 2023/11/11 15:15 # @File : apscheduler.py # @Description : """ from flask_apscheduler import APScheduler as BaseAPScheduler class APScheduler(BaseAPScheduler): """ A custom APScheduler with context management. This allows the scheduler to work with Flask's application context, which is necessary for tasks that interact with the database. """ def run_job(self, _id, _job=None): """ Run a job with Flask's application context. :param _id: The ID of the job to run. :param _job: The job store alias. """ with self.app.app_context(): super().run_job(id=_id, jobstore=_job)