Celery Getting Started

Source: Internet
Author: User

The asynchronous task script tasks.py will be executed:

 fromCeleryImportCelery fromCeleryImportGroup#host= ' 10.32.21.52 ', port=6379, db=3App = Celery ('Tasks', backend ='REDIS://10.32.21.52:6379/14', broker='REDIS://10.32.21.52:6379/15') @app. TaskdefAdd (x, y):returnX +Y@app.taskdefTsum (ITE):returnsum (ITE) @app. Task (Trail=True)defA (how_many):returnGroup (B.S (i) forIinchRange (How_many)) () @app. Task (Trail=True)defB (i):returnPow2.delay (i) @app. Task (Trail=True)defPow2 (i):returnI * * 2

Where: Celery in the app configuration, detailed configuration can refer to the document: http://docs.celeryproject.org/en/latest/getting-started/ First-steps-with-celery.html#configuration

To start a task:

Celery-a Tasks worker--loglevel=info

The output after startup, displaying the server and configuration information and task running log;

To invoke a task through a script:

 fromTasksImportAdd fromTasksImportTsum fromTasksImportA fromCeleryImportChordresult= Add.delay (4, 4)~tsum.map ([Range], range (100)])~add.starmap ([item forIteminchZip (range), range (10))])#Chord (Add.s (i, I) for I in Xrange ()) (TSUM.S ()). Get ()Chord ((Add.s (i, i) forIinchXrange (100) ), TSUM.S ()) () Add.chunks (Zip (xrange (, xrange (100)), 10)()Print(result.backend)Printresult.get () result= A.delay (10)

Write the task is too simple, than a single machine is slow, only on the crawl task to try ~

Celery uses the adorner to abstract each task into a plug-in dispatch that sends a message to a third party, such as Redis, and then assigns the task to each machine that initiates the celery service to perform the task, and then to explore the source code and continue to share it.

Celery Getting Started

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.