apscheduler.py 866 Bytes
Newer Older
崔为之's avatar
崔为之 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/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)