celery-1

# celery

1. Concept

The basic concept: Broker, Backend

What is a broker?

a broker middleware message transmission, can be understood as a queue. Whenever an application calls celery asynchronous tasks, it will deliver a message to the broker, then the celery worker will take to the message, the corresponding program execution.
Broker in Chinese means 'broker', in fact, Message Queuing, used to send and receive messages.
Broker There are several options to choose from: RabbitMQ, Redis, database (not recommended), and so on.

What is a backend?

A major issue is how to ensure that asynchronous procedure returns the corresponding result processor.
for information related to the information storage backend processor and executed.
Backend Celery is a configuration item in the configuration CELERY_RESULT_BACKEND, save the results and the role of the state, if you need to track the status of tasks, you need to set this one, can be a Database backend, can also be a Cache backend, concrete can be found here: CELERY_RESULT_BACKEND.

For brokers, the official recommendation is rabbitmq and redis, As backend, is the database. For simplicity can use redis.

1.1 Architecture

Celery architecture consists of three parts, the middleware message (message broker), the task execution unit (worker) and task execution result storage (task result store) composition.

Messaging middleware
Celery itself does not provide messaging services, but can be easily and messaging middleware integration provided by third parties. Including, RabbitMQ, Redis, MongoDB (experimental ), Amazon SQS (experimental), CouchDB (experimental), SQLAlchemy (experimental), Django ORM (experimental), IronMQ

Task execution unit
Worker Task Celery unit is provided to perform, worker operating in a distributed concurrent system node.

Task results are stored
Task result store to store results of execution of the tasks Worker, Celery support results in different ways to store tasks, including AMQP, redis, memcached, mongodb, SQLAlchemy, Django ORM, Apache Cassandra, IronCache and so on.

beat
fact, there is a component of the beat, worker can be regarded as cycling twisted, just take charge of the task from the queue, execution and returns a result;
if not added to the task queue task worker will be idle;

There are two ways to add a task:
Delay is added in one task Task that is the async;
Beat responsible for periodically add tasks to the task queue;

Chart:

2. Install

pip install celery

Guess you like

Origin www.cnblogs.com/wodeboke-y/p/11600926.html