且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Django管理命令在cron中不起作用

更新时间:2023-08-24 12:50:04

我找到了问题的原因。

它非常非常 非常

问题有两个:


  1. 没有 USER cron作业中的环境变量;仅 LOGNAME ;

  2. 下运行 manage.py 时一个指定的管理命令,如果在导入设置模块期间引发异常,则Django 安静地会故障转移为空白设置。

  1. There is no USER environment variable in a cron job; only LOGNAME;
  2. When manage.py is run with a management command specified, Django quietly fails over to blank settings if an exception is raised during the import of the settings module.

我的设置模块正在尝试引用 os.environ ['USER'] ,在cron的环境中不存在。因此,导入设置模块会引发异常,而Django会悄悄地故障转移为空白设置,这意味着空白 INSTALLED_APPS 且没有 celery 命令!

My settings module was trying to reference os.environ['USER'], which doesn't exist in cron's environment. So importing the settings module causes an exception to be raised, and Django quietly fails over to blank settings, which means blank INSTALLED_APPS and no celery command!