19 lines
519 B
Python
19 lines
519 B
Python
![]() |
import os
|
||
|
from celery import Celery
|
||
|
from django.conf import settings
|
||
|
|
||
|
# 设置Django默认settings模块
|
||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'daren_project.settings')
|
||
|
|
||
|
# 创建Celery应用
|
||
|
app = Celery('daren_project')
|
||
|
|
||
|
# 使用Django settings的CELERY_配置值
|
||
|
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||
|
|
||
|
# 自动发现并注册tasks模块中的任务
|
||
|
app.autodiscover_tasks()
|
||
|
|
||
|
@app.task(bind=True, ignore_result=True)
|
||
|
def debug_task(self):
|
||
|
print(f'Request: {self.request!r}')
|