Python Task Scheduler module celery

Source: Internet
Author: User
Tags rabbitmq install redis

Python Task Scheduler module celeryCelery IntroductionCelery Featurescelery Work Flow chartcelery installation and use

Python Task Scheduler module celeryCelery Introduction

Celery is a python-developed asynchronous distributed task scheduling module.
Celery itself does not provide messaging services, using third-party services, or Borker, to deliver tasks, typically using RABBITMQ or Redis.

Celery Features
  • Simple: Once you are familiar with the celery workflow, the configuration and use is relatively simple.
  • High availability: Celery automatically attempts to re-execute a task when the task execution fails or a connection break occurs during execution.
  • Fast: A single-process celery can handle millions of tasks per minute.
  • Flexible: Almost celery components can be expanded and customized.
celery Work Flow chart Write a picture description here celery installation and use

Installing the Celery module

pip install celery

The default broker for celery is RABBITMQ, only one line is required

broker_url‘amqp://guest:[email protected]:5672//‘

Redis is also available as a broker.

Installation

pip install redis

Configuration
Broker_url Configure the Redis database address in the format Redis://:[email protected]:p ort/db_number.
The backend configures the task Results store location and saves the execution results for each task.

app.conf.broker_url =  redis://localhost:6379/0 '  
App.conf.result_backend = ' redis://localhost:6379/0 '
Port and Db_number are optional, by default the lower port uses the 6379,db_number using 0.

Example
Create a Celery application definition task list, creating a new celery1.py file

 fromCeleryImportCelery
Broker ="REDIS://118.24.18.158:6379/5"
Backend ="REDIS://118.24.18.158:6379/6"
App = Celery ("Celery1", Broker=broker, Backend=backend)
@app. Task
def add(x, y):
returnX+y

Start celery worker start listening and performing tasks

celery -A celery1 worker --loglevel=info

Invoke task

Import Time
From Celery1 Import add
Re = Add.delay (Ten, -)
Print(RE)
Print(Re.Status)
Time. Sleep (8)
Print(Re.Status)
Print(Re.result)

Python Task Scheduler module celery

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.