#!/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 14:50 # @File : init_apscheduler.py # @Description : Initializes the APScheduler extension for a Flask application. """ from flask import Flask from apscheduler.triggers.interval import IntervalTrigger from application.libs.flask_apscheduler import APScheduler from application.libs.tasks import task # Initialize APScheduler scheduler = APScheduler() def init_tasks(app: Flask) -> None: """ Initializes the task extension for a Flask application. Args: app (Flask): The Flask application. Returns: None Raises: TypeError: If the provided argument is not a Flask application instance. """ if not isinstance(app, Flask): raise TypeError(f'Expected a Flask application instance, got {type(app).__name__}') scheduler.api_enabled = True scheduler.init_app(app) # Create an interval trigger interval = IntervalTrigger( days=1, start_date=app.config.Scheduler.Start, end_date=app.config.Scheduler.End, timezone=app.config.Scheduler.Timezone) # Add a job to the scheduler scheduler.add_job(func=task, trigger=interval, id='task_one') # Start the scheduler scheduler.start()