init_celery.py 691 Bytes
Newer Older
崔为之's avatar
崔为之 committed
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/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/7 16:10
# @File        : init_celery.py
# @Description :
"""

from flask import Flask
崔为之's avatar
崔为之 committed
14
from celery.schedules import crontab
崔为之's avatar
崔为之 committed
15

崔为之's avatar
崔为之 committed
16
from application.utils import make_celery
崔为之's avatar
崔为之 committed
17 18


崔为之's avatar
崔为之 committed
19
def init_celery(app: Flask) -> None:
崔为之's avatar
崔为之 committed
20 21 22 23 24 25 26 27 28
    celery = make_celery(app)
    app.celery = celery

    celery.conf.beat_schedule = {
        'update-database-every-day': {
            'task': 'application.libs.tasks.task.update_database',
            'schedule': crontab(minute='*')  # Execute every minute
        }
    }