feat(celery): 添加定时清理过期临时文件任务

This commit is contained in:
xiaji
2026-05-25 21:09:43 +08:00
parent ce7d39f36c
commit aba4933a95

View File

@@ -1,6 +1,7 @@
import os
from celery import Celery
from django.conf import settings
from celery.schedules import crontab
# 设置默认的Django设置模块
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)
# 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)
def debug_task(self):
"""调试任务"""