修复了一些可能影响生产的问题
This commit is contained in:
@@ -1,16 +1,6 @@
|
||||
"""
|
||||
ASGI config for a_long_dianjing project.
|
||||
|
||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'a_long_dianjing.settings')
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'a_long_dianjing.settings')
|
||||
application = get_asgi_application()
|
||||
|
||||
@@ -12,27 +12,24 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'a_long_dianjing.settings')
|
||||
|
||||
# 创建Celery应用实例
|
||||
app = Celery('a_long_dianjing')
|
||||
|
||||
# 从Django settings中加载Celery配置(CELERY_前缀)
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
|
||||
# 自动发现所有已注册app中的tasks.py文件
|
||||
#app.autodiscover_tasks()
|
||||
app.autodiscover_tasks(['yonghu.tasks', 'yonghu.ranking_tasks', 'dingdan.tasks', 'peizhi.tasks'])
|
||||
app.autodiscover_tasks(['users.tasks', 'users.ranking_tasks', 'orders.tasks', 'config.tasks'])
|
||||
|
||||
# 配置周期性任务(Celery Beat Schedule)
|
||||
app.conf.beat_schedule = {
|
||||
|
||||
# 月榜数据转移(每月最后一天23:50执行)
|
||||
'yuebang_zhuanyi': {
|
||||
'task': 'yonghu.ranking_tasks.zhuanyi_yuebang',
|
||||
'task': 'users.ranking_tasks.zhuanyi_yuebang',
|
||||
'schedule': crontab(hour=23, minute=50, day_of_month='28-31'), # ✅ 修改这里
|
||||
'options': {'queue': 'periodic_tasks', 'priority': 7},
|
||||
},
|
||||
|
||||
# 日榜数据转移(每天23:55执行,在清零前)
|
||||
'ribang_zhuanyi': {
|
||||
'task': 'yonghu.ranking_tasks.zhuanyi_ribang',
|
||||
'task': 'users.ranking_tasks.zhuanyi_ribang',
|
||||
#'schedule': crontab(minute='*/1'), # 每分钟执行一次,测试用
|
||||
'schedule': crontab(hour=23, minute=55), # 每天23:55
|
||||
'options': {'queue': 'periodic_tasks', 'priority': 7}, # 优先级高于清零任务
|
||||
@@ -40,21 +37,21 @@ app.conf.beat_schedule = {
|
||||
|
||||
# 清理旧历史数据(每月1号凌晨1点执行)
|
||||
'qingli_jiulishuju': {
|
||||
'task': 'yonghu.ranking_tasks.qingli_jiulishuju',
|
||||
'task': 'users.ranking_tasks.qingli_jiulishuju',
|
||||
'schedule': crontab(hour=1, minute=0, day_of_month=1), # 每月1号凌晨1点
|
||||
'options': {'queue': 'periodic_tasks', 'priority': 4},
|
||||
},
|
||||
|
||||
# 补偿检查任务(每5分钟运行)
|
||||
'check_order_expire_task': {
|
||||
'task': 'dingdan.tasks.check_order_expire_task',
|
||||
'task': 'orders.tasks.check_order_expire_task',
|
||||
'schedule': crontab(minute='*/5000'),
|
||||
'options': {'queue': 'order_tasks', 'priority': 3},
|
||||
},
|
||||
|
||||
# 1. 每日凌晨0点执行 - 清零任务
|
||||
'daily_reset_task': {
|
||||
'task': 'yonghu.tasks.daily_reset_task',
|
||||
'task': 'users.tasks.daily_reset_task',
|
||||
'schedule': crontab(hour=0, minute=0), # 每天0点
|
||||
'options': {
|
||||
'queue': 'periodic_tasks',
|
||||
@@ -66,7 +63,7 @@ app.conf.beat_schedule = {
|
||||
|
||||
# 2. 每月1日凌晨0点执行 - 月度清零任务
|
||||
'monthly_reset_task': {
|
||||
'task': 'yonghu.tasks.monthly_reset_task',
|
||||
'task': 'users.tasks.monthly_reset_task',
|
||||
'schedule': crontab(hour=0, minute=0, day_of_month=1), # 每月1日0点
|
||||
'options': {
|
||||
'queue': 'periodic_tasks',
|
||||
@@ -78,7 +75,7 @@ app.conf.beat_schedule = {
|
||||
|
||||
# 4. 每天凌晨0点5分清理收支记录
|
||||
'daily_sz_reset_task': {
|
||||
'task': 'peizhi.tasks.daily_sz_reset_task',
|
||||
'task': 'config.tasks.daily_sz_reset_task',
|
||||
'schedule': crontab(hour=0, minute=5), # 每天0点5分
|
||||
'options': {
|
||||
'queue': 'periodic_tasks',
|
||||
@@ -90,66 +87,15 @@ app.conf.beat_schedule = {
|
||||
}
|
||||
|
||||
|
||||
# 配置周期性任务(Celery Beat Schedule)
|
||||
'''app.conf.beat_schedule = {
|
||||
# 1. 每日凌晨0点执行 - 清零任务
|
||||
'daily_reset_task': {
|
||||
'task': 'yonghu.tasks.daily_reset_task',
|
||||
'schedule': crontab(hour=0, minute=0), # 每天0点
|
||||
'options': {
|
||||
'queue': 'periodic_tasks',
|
||||
'priority': 5
|
||||
},
|
||||
'args': (),
|
||||
'kwargs': {}
|
||||
},
|
||||
|
||||
# 2. 每月1日凌晨0点执行 - 月度清零任务
|
||||
'monthly_reset_task': {
|
||||
'task': 'yonghu.tasks.monthly_reset_task',
|
||||
'schedule': crontab(hour=0, minute=0, day_of_month=1), # 每月1日0点
|
||||
'options': {
|
||||
'queue': 'periodic_tasks',
|
||||
'priority': 5
|
||||
},
|
||||
'args': (),
|
||||
'kwargs': {}
|
||||
},
|
||||
|
||||
# 3. 每5分钟检查一次待处理订单 - 作为补偿机制
|
||||
'check_order_expire_task': {
|
||||
'task': 'dingdan.tasks.check_order_expire_task',
|
||||
'schedule': crontab(minute='*/5'), # 每5分钟
|
||||
'options': {
|
||||
'queue': 'order_tasks',
|
||||
'priority': 3
|
||||
},
|
||||
'args': (),
|
||||
'kwargs': {}
|
||||
},
|
||||
|
||||
# 4. 每天凌晨0点5分清理收支记录
|
||||
'daily_sz_reset_task': {
|
||||
'task': 'peizhi.tasks.daily_sz_reset_task',
|
||||
'schedule': crontab(hour=0, minute=5), # 每天0点5分
|
||||
'options': {
|
||||
'queue': 'periodic_tasks',
|
||||
'priority': 4
|
||||
},
|
||||
'args': (),
|
||||
'kwargs': {}
|
||||
}
|
||||
}'''
|
||||
|
||||
# 时区设置
|
||||
app.conf.timezone = 'Asia/Shanghai'
|
||||
app.conf.enable_utc = True
|
||||
|
||||
# 队列路由配置
|
||||
app.conf.task_routes = {
|
||||
'dingdan.tasks.*': {'queue': 'order_tasks'},
|
||||
'yonghu.tasks.*': {'queue': 'periodic_tasks'},
|
||||
'peizhi.tasks.*': {'queue': 'periodic_tasks'},
|
||||
'orders.tasks.*': {'queue': 'order_tasks'},
|
||||
'users.tasks.*': {'queue': 'periodic_tasks'},
|
||||
'config.tasks.*': {'queue': 'periodic_tasks'},
|
||||
}
|
||||
|
||||
# 任务序列化
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# celery_app.py
|
||||
import os
|
||||
from celery import Celery
|
||||
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'a_long_dianjing.settings')
|
||||
|
||||
app = Celery('a_long_dianjing')
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
# 手动导入任务模块,避免与已有 tasks.py 冲突
|
||||
app.autodiscover_tasks(['dingdan.notice_tasks'])
|
||||
app.autodiscover_tasks(['orders.notice_tasks'])
|
||||
|
||||
@@ -3,14 +3,13 @@ Django settings for a_long_dianjing project.
|
||||
"""
|
||||
from pathlib import Path
|
||||
from datetime import timedelta
|
||||
import os
|
||||
|
||||
# 从密钥配置文件导入敏感信息
|
||||
try:
|
||||
import app_secrets
|
||||
except ImportError:
|
||||
raise ImportError("缺少 appapp_secrets.py 密钥配置文件,请参照项目说明创建")
|
||||
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
SECRET_KEY = app_secrets.SECRET_KEY
|
||||
|
||||
@@ -1,32 +1,7 @@
|
||||
"""
|
||||
URL configuration for a_long_dianjing project.
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/6.0/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
'''from django.contrib import admin
|
||||
from django.urls import path
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
]'''
|
||||
|
||||
# a_long_dianjing/urls.py
|
||||
"""
|
||||
项目根路由配置 - 按照生产环境格式,连接所有APP路由
|
||||
注意:本项目使用MinIO模拟OSS,文件上传不经过Django MEDIA_URL,所以不需要static(settings.MEDIA_URL)配置
|
||||
"""
|
||||
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
"""
|
||||
WSGI config for a_long_dianjing project.
|
||||
|
||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'a_long_dianjing.settings')
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'a_long_dianjing.settings')
|
||||
application = get_wsgi_application()
|
||||
|
||||
Reference in New Issue
Block a user