使用 Django+Celery 进行开发而不运行 `celeryd`?

发布于 2024-09-26 05:04:08 字数 81 浏览 1 评论 0原文

在开发中,运行 celeryd 以及 Django 开发服务器有点麻烦。例如,是否可以要求 celery 在开发过程中同步运行任务?或者类似的东西?

In development, it's a bit of a hassle to run the celeryd as well as the Django development server. Is it possible to, for example, ask celery to run tasks synchronously during development? Or something similar?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

铁憨憨 2024-10-03 05:04:08

是的,您可以通过在设置中设置 CELERY_TASK_ALWAYS_EAGER = True 来实现此目的。
(常量以前称为CELERY_ALWAYS_EAGER
http://docs.celeryproject.org/en/最新/userguide/configuration.html#task-execution-settings

Yes you can do this by setting CELERY_TASK_ALWAYS_EAGER = True in your settings.
(Constant was previously called CELERY_ALWAYS_EAGER)
http://docs.celeryproject.org/en/latest/userguide/configuration.html#task-execution-settings

很糊涂小朋友 2024-10-03 05:04:08

django-celery 中还有一个自定义 Django 测试运行器,可以帮助处理 CELERY_ALWAYS_EAGER。
阅读有关在 Django 中使用 Celery 的更多信息 文档

There's also a custom Django test runner in django-celery that helps with CELERY_ALWAYS_EAGER.
Read more about using Celery with Django on the docs.

暮年 2024-10-03 05:04:08

在 Celery 的 4.0 版本中,CELERY_ALWAYS_EAGER 设置已替换为 Django settings.pytask_always_eager< 中的 CELERY_TASK_ALWAYS_EAGER /code> 原生位于 celeryconf 中。

由于 celery 配置从 3.x 版本到 4.x 版本的大量更改分布在许多行中,因此我建议使用内置的设置迁移工具。

celery升级设置--django

来源:

幸运的是,您不必手动更改文件,因为 celery
升级设置--django 程序应该做正确的事情。

http:// docs.celeryproject.org/en/latest/whatsnew-4.0.html#step-4-upgrade-to-celery-4-0

In version 4.0 of Celery CELERY_ALWAYS_EAGER setting was replaced by CELERY_TASK_ALWAYS_EAGER in Django settings.py or task_always_eager natively in celery conf.

Since the numerous changes in the celery configuration from version 3.x to 4.x are spread over many lines, I suggest to use the built-in settings migration tool.

celery upgrade settings --django

source:

Luckily you don’t have to manually change the files, as the celery
upgrade settings --django program should do the right thing.

http://docs.celeryproject.org/en/latest/whatsnew-4.0.html#step-4-upgrade-to-celery-4-0

兔姬 2024-10-03 05:04:08

经过 5 年多的编写 Celery 任务后,我注意到我开发的一种模式可以帮助测试和简化开发 - 我意识到,如果我的 Celery 任务是我通常放入 < 中的常规 Python 函数的薄包装器,那就更好了代码>myproject.impl包。 Celery 任务可能包含一些严格与 Celery 相关的逻辑,例如使用分布式锁定、显式重试逻辑等。

After 5+ years of writing Celery tasks I have noticed a pattern I have developed that can help with testing and ease of development - I realised it is much better if my Celery tasks are thin wrappers around the regular Python functions that I typically put in myproject.impl package. Celery tasks may contain some strictly Celery related logic, like using distributed locking for an example, explicit retry logic, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文