简体   繁体   English

如何在芹菜中推送和弹出队列的任务

[英]How to push and pop tasks of the queue in celery

I want to save large amount of images to the image server. 我想将大量图像保存到图像服务器。 I need to queue all requests of images information for saving them using Celery.I use Django framework. 我需要将所有图像信息请求排队以使用Celery保存它们。我使用Django框架。 I read the document of Celery and configured it in Django and,I also created a queue under the name "images", but I don't know how to put information of images to the queue and send message for saving and remove them from the queue after saving. 我阅读了Celery的文档,并在Django中对其进行了配置,并且还创建了一个名为“ images”的队列,但是我不知道如何将图像信息放入该队列并发送消息以将其保存并从中删除。保存后排队。 I couldn't find any command for push and pop tasks in queue in the document of Celery. 我在Celery文档的队列中找不到任何用于推送和弹出任务的命令。

Here is the code of how I configured the celery: 这是我配置芹菜的代码:

from kombu import Exchange, Queue
from celery import Celery
import os

class CeleryQueue:

   def celery_queue(self):

       os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'DataScience.settings')
       app = Celery('images', broker='amqp://localhost')
       app.config_from_object('django.conf:settings', namespace='CELERY')
       app.autodiscover_tasks()
       image_exchange = Exchange('media', type='direct')
       app.conf.task_default_queue = 'images'
       app.conf.task_default_exchange_type = 'direct'
       app.conf.task_default_routing_key = 'media.image'
       app.conf.task_queues = (Queue('images', image_exchange,routing_key=app.conf.task_default_routing_key))

Thank you for any help 感谢您的任何帮助

I think you are confused reading the documentation. 我认为您在阅读文档时感到困惑。 The queue is used to store tasks. 队列用于存储任务。 Tasks are written as functions and decorated with @task. 任务被编写为函数,并以@task修饰。 So when you call a task use task_name.delay(parameters) 因此,当您调用任务时,请使用task_name.delay(parameters)

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

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