简体   繁体   English

Django和Celery任务

[英]Django and Celery tasks

So in our Django project we're using Celery and the Django-Celery module. 因此,在我们的Django项目中,我们使用Celery和Django-Celery模块。 The person that originally wrote the tasks section wrote it like so: 最初编写任务部分的人这样写:

from djcelery import celery

@celery.task
def do_something():
    ...

But everywhere in the docs it shows that we should create a separate celery.py file and import the app like so: 但是在文档中的每个地方都表明我们应该创建一个单独的celery.py文件,并按如下所示导入应用程序:

celery.py 芹菜

from celery import Celery

app = Celery('project')
if __name__=='__main__':
    app.run()

tasks.py tasks.py

from celery import app # Importing `app` from our celery.py

@app.task
def do_something():
    ...

So I'm wondering if there's a problem doing it one way or the other? 所以我想知道以一种方式或另一种方式进行操作是否有问题? We're using django-celery version 3.1 我们正在使用django-celery版本3.1

First page in start with celery documentation 芹菜文档开始的第一页

Previous versions of Celery required a separate library to work with Django, but since 3.1 this is no longer the case. 以前版本的Celery需要一个单独的库才能与Django一起使用,但是从3.1开始,情况不再如此。 Django is supported out of the box now so this document only contains a basic way to integrate Celery and Django. 现成的支持Django,因此本文档仅包含集成Celery和Django的基本方法。 You'll use the same API as non-Django users so you're recommended to read the First Steps with Celery tutorial first and come back to this tutorial. 您将使用与非Django用户相同的API,因此建议您先阅读“使用Celery的第一步”教程,然后再返回本教程。 When you have a working example you can continue to the Next Steps guide. 当您有可用的示例时,可以继续阅读“下一步”指南。

Also first line of readme for django-celery states following 也是以下django-celery状态的第一行自述文件

Old django celery integration project. 老django芹菜整合项目。

To summarize following, django-celery is old approach used by your app and new documentation follows new way of handling celery 总结一下,django-celery是您的应用程序使用的旧方法,而新文档遵循了处理celery的新方法

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

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