简体   繁体   English

FastAPI后台任务和Celery任务有什么区别?

[英]What's the difference between FastAPI background tasks and Celery tasks?

Recently I read something about this and the point was that celery is more productive.最近我读了一些关于这个的东西,重点是 celery 更有效率。

Now, I can't find detailed information about the difference between these two and what should be the best way to use them.现在,我找不到关于这两者之间的区别以及使用它们的最佳方式的详细信息。

Straight from the documentation :直接来自 文档

If you need to perform heavy background computation and you don't necessarily need it to be run by the same process (for example, you don't need to share memory, variables, etc), you might benefit from using other bigger tools like Celery .如果您需要执行繁重的后台计算并且您不一定需要它由同一进程运行(例如,您不需要共享 memory、变量等),您可能会受益于使用其他更大的工具,如Celery

They tend to require more complex configurations, a message/job queue manager, like RabbitMQ or Redis, but they allow you to run background tasks in multiple processes , and especially, in multiple servers.它们往往需要更复杂的配置,消息/作业队列管理器,如 RabbitMQ 或 Redis,但它们允许您在多个进程中运行后台任务,尤其是在多个服务器中。

To see an example, check the Project Generators , they all include Celery already configured.要查看示例,请检查项目生成器,它们都包含已配置的 Celery。

But if you need to access variables and objects from the same FastAPI app, or you need to perform small background tasks (like sending an email notification), you can simply just use BackgroundTasks .但是,如果您需要从同一个FastAPI 应用程序访问变量和对象,或者您需要执行小型后台任务(例如发送 email 通知),您只需使用BackgroundTasks即可。

Have a look at this answer as well.也看看这个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM