feat(celery): 添加定时清理过期临时文件任务
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from celery import Celery
|
from celery import Celery
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from celery.schedules import crontab
|
||||||
|
|
||||||
# 设置默认的Django设置模块
|
# 设置默认的Django设置模块
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'diary_family.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'diary_family.settings')
|
||||||
@@ -14,6 +15,14 @@ app.config_from_object('django.conf:settings', namespace='CELERY')
|
|||||||
# 自动发现任务
|
# 自动发现任务
|
||||||
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
||||||
|
|
||||||
|
# Celery Beat 周期任务配置
|
||||||
|
app.conf.beat_schedule = {
|
||||||
|
'cleanup-expired-temp-files': {
|
||||||
|
'task': 'core.tasks.cleanup_expired_temp_files',
|
||||||
|
'schedule': crontab(minute=0), # 每小时整点执行
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
@app.task(bind=True)
|
@app.task(bind=True)
|
||||||
def debug_task(self):
|
def debug_task(self):
|
||||||
"""调试任务"""
|
"""调试任务"""
|
||||||
|
|||||||
Reference in New Issue
Block a user