如何在Windows机器上用Django测试芹菜 [英] How to test celery with django on a windows machine
问题描述
我正在寻找有关如何在基于Linux的服务器上进行部署之前在Windows计算机上测试django celery的资源,文档或建议。
I'm looking for a resource, documentation or advise on how to test django celery on my windows machine before deploying on a Linux based server.
任何有用的答案
推荐答案
Celery(由于另一个答案指出的版本4)不支持Windows(来源: http://docs.celeryproject.org/en/latest /faq.html#does-celery-support-windows )。即便如此,您仍然可以选择:
Celery (since version 4 as pointed out by another answer) does not support Windows (source: http://docs.celeryproject.org/en/latest/faq.html#does-celery-support-windows). Even so, you have some options:
1)使用 task_always_eager = True
。这将同步运行您的任务-通过此操作,您可以验证您的代码是否正在执行预期的操作。甚至在Windows上也可以同步运行任务。
1) Use task_always_eager=True
. This will run your tasks synchronously – with this, you can verify that your code is doing what it's supposed to do. Running tasks synchronously works even on Windows.
更多信息: http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-task_always_eager
2)使用WSL(Linux的Windows子系统)。
2) Use WSL (Windows Subsystem for Linux).
更多信息: https://docs.microsoft.com/zh-cn/windows/wsl/install-win10#install-the-windows-subsystem-for-linux
3)将Docker用于Windows。您可以在容器内运行Celery Worker和Celery Beat。
3) Use Docker for Windows. You can run Celery Worker(s) and Celery Beat inside the container.
更多信息: https://docs.docker.com/docker-for-windows/
我个人使用选项 1)用于单元测试,选项 2)用于开发。
Personally, I use option 1) for unit testing and option 2) for development.
这篇关于如何在Windows机器上用Django测试芹菜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!