• django配置文件环境分离后celery的启动方式整理


    django项目中,当配置文件分离时:

    启动方式1:

    硬编码写死在manage.py中:

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dbmanager.settings.test")

    方式2:

    命令行启动时,指定对应环境:(会覆盖manage.py中的配置)

    python manage.py runserver --settings=dbmanager.settings.production 0.0.0.0:8000

    celery启动:

    
    
    
    version: '2'
    services:
      redis-local:
        image: harbor.asd.com/yw/dbm-redis:v_test_master_20190507.072141
        ports:
          - "6379:6379"
        volumes:
          - /etc/localtime:/etc/localtime:ro
    
      dbmanager:
        container_name: dbmanager-service
        image: harbor.asd.com/yw/dbmanager:v_pro_master_20190518.170636
        working_dir: /usr/src/app/dbmanager
        command:
          - /bin/sh
          - -c
          - |
            python manage.py crontab add
            crond
            python manage.py runserver --settings=dbmanager.settings.production 0.0.0.0:8000
        ports:
          - "8000:8000"
        volumes:
          - /etc/localtime:/etc/localtime:ro
          - /data/usr/src/app/dbmanager/log:/usr/src/app/dbmanager/log:rw
        depends_on:
          - redis-local
    
      celery-beat:
        container_name: celery-beat
        image: harbor.asd.com/yw/dbmanager:v_pro_master_20190518.170636
        working_dir: /usr/src/app/dbmanager
        command: python manage.py celery -A dbmanager beat -l info   # 需要在manage.py文件中指定os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dbmanager.settings.test") 配置环境,celery启动就可以找到对应环境启动,无需命令行指定配置文件环境
        volumes:
          - /etc/localtime:/etc/localtime:ro
        depends_on:
          - redis-local
    
      celery-worker:
        container_name: celery-worker
        image: harbor.asd.com/yw/dbmanager:v_pro_master_20190518.170636
        working_dir: /usr/src/app/dbmanager
        command: python manage.py celery -A dbmanager worker -l info
        volumes:
          - /etc/localtime:/etc/localtime:ro
          - /data/usr/src/app/dbmanager/slowlogs:/data/slowlogs:rw
        depends_on:
          - redis-local
    
      celery-flower:
        container_name: celery-flower
        image: harbor.asd.com/yw/dbmanager:v_pro_master_20190518.170636
        working_dir: /usr/src/app/dbmanager
    配置文件拆分后,django启动报错:
    
    mproperlyConfigured: The SECRET_KEY setting must not be empty.
    
    错误原因:
    
    manage.py中米有settigs的路径没有配置正确,导致执行的时候访问不到settings.py,所以报错
    
    解决办法:
    
    在manage.py中添加具体的配置文件即可
    
    if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "meiduo_mall.settings.dev")
  • 相关阅读:
    面试题
    面向切面编程 AOP
    matlab提取wind底层数据库操作
    tensorflow(4):神经网络框架总结
    tensorflow(3):神经网络优化(ema,regularization)
    tensorflow(2):神经网络优化(loss,learning_rate)
    tensorflow(1) 基础: 神经网络基本框架
    在anaconda中安装tensorflow
    anaconda利用pip安装module
    python(10): xlsxwriter模块
  • 原文地址:https://www.cnblogs.com/yum777/p/10896131.html
Copyright © 2020-2023  润新知