如何在 Windows 机器上使用 django 测试 celery

Jef*_*idi 2 django django-models rabbitmq redis celery

我正在寻找有关如何在基于 Linux 的服务器上部署之前在我的 Windows 机器上测试 django celery 的资源、文档或建议。

任何有用的答案将不胜感激和接受。

ill*_*nan 9

Celery(从另一个答案指出的第 4 版开始)不支持 Windows(来源:http : //docs.celeryproject.org/en/latest/faq.html#does-celery-support-windows)。即便如此,您仍有一些选择:

1)使用task_always_eager=True。这将同步运行您的任务——通过这个,您可以验证您的代码正在做它应该做的事情。即使在 Windows 上也可以同步运行任务。

更多信息:http : //docs.celeryproject.org/en/latest/userguide/configuration.html#std : setting-task_always_eager

2)使用 WSL(适用于 Linux 的 Windows 子系统)。

更多信息:https : //docs.microsoft.com/en-us/windows/wsl/install-win10#install-the-windows-subsystem-for-linux

3)使用 Docker for Windows。您可以在容器内运行 Celery Worker(s) 和 Celery Beat。

更多信息:https : //docs.docker.com/docker-for-windows/

就个人而言,我使用选项1)进行单元测试,使用选项2)进行开发。