Files

26 lines
941 B
Python
Raw Permalink 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 django.apps import AppConfig
class CoreConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "apps.core"
verbose_name = "核心模块"
def ready(self):
"""Django 启动时即初始化 dramatiq 全局 broker。
关键:dramatiq 默认 get_broker() 会惰性创建"无 url 的 localhost RedisBroker",
完全不读 REDIS_URL 环境变量。必须在任何 actor 模块被 import 之前
加载 config.broker,把全局 broker 设为正确的 Redis 实例(或测试 StubBroker),
否则 .send() 会连 localhost:6379 报 Connection refused。
"""
if os.environ.get("TASK_BROKER") == "disabled":
return
try:
from config.broker import broker # noqa: F401
except Exception:
# broker 初始化失败不应阻断 Django 启动(如迁移/构建场景)
pass