KeywordRetriever/KeywordRetriever/celery.py

21 lines
583 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from celery import Celery
# 设置环境变量
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'KeywordRetriever.settings')
# 实例化
app = Celery('KeywordRetriever')
# namespace='CELERY'作用是允许你在Django配置文件中对Celery进行配置
# 但所有Celery配置项必须以CELERY开头防止冲突
app.config_from_object('django.conf:settings', namespace='CELERY')
# 自动从Django的已注册app中发现任务
app.autodiscover_tasks()
# # 一个测试任务
# @app.task(bind=True)
# def debug_task(self):
# print(f'Request: {self.request!r}')