如何在 Windows 机器上使用 django 测试 celery [英] How to test celery with django on a windows machine

查看:34
本文介绍了如何在 Windows 机器上使用 django 测试 celery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关如何在基于 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.

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

Any useful Answer would be appreciated and accepted.

推荐答案

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/en-us/windows/wsl/install-win10#install-the-windows-subsystem-for-linux

3) 使用 Docker for Windows.您可以在容器内运行 Celery Worker(s) 和 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 测试 celery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆