分布式异步任务Celery
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了分布式异步任务Celery相关的知识,希望对你有一定的参考价值。
-A代表APP celery -A tasks worker --loglevel=info -n nodemaster -------------- [email protected] v4.1.0 (latentcall) ---- **** ----- --- * *** * -- Darwin-17.3.0-x86_64-i386-64bit 2018-04-15 11:53:09 -- * - **** --- - ** ---------- [config] - ** ---------- .> app: tasks:0x110b42400 - ** ---------- .> transport: redis://localhost:6379/0 - ** ---------- .> results: disabled:// - *** --- * --- .> concurrency: 4 (prefork) -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker) --- ***** ----- -------------- [queues] .> celery exchange=celery(direct) key=celery [tasks] . tasks.sendmail [2018-04-15 11:53:09,217: INFO/MainProcess] Connected to redis://localhost:6379/0 [2018-04-15 11:53:09,228: INFO/MainProcess] mingle: searching for neighbors [2018-04-15 11:53:10,256: INFO/MainProcess] mingle: sync with 2 nodes [2018-04-15 11:53:10,257: INFO/MainProcess] mingle: sync complete [2018-04-15 11:53:10,270: INFO/MainProcess] [email protected] ready. celery -A tasks inspect registered celery -A tasks inspect registered -> [email protected]: OK * tasks.sendmail -> [email protected]: OK * tasks.sendmail Python 3.4.3 (default, Nov 6 2015, 22:26:48) [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from tasks import sendmail >>> sendmail.delay(dict(to=‘[email protected]‘)) <AsyncResult: b49534cd-472f-42da-934c-057e53e0d0a8> >>> sendmail.delay(dict(to=‘[email protected]‘)) <AsyncResult: 99cd7565-612a-4b31-b025-de7b5c48673c> >>> sendmail.delay(dict(to=‘[email protected]‘)) <AsyncResult: bd123165-d220-4552-bcb8-e009c76258d7> >>> sendmail.delay(dict(to=‘[email protected]‘)) <AsyncResult: 01a8ef22-149c-4b24-8d92-f07468598646> >>> sendmail.delay(dict(to=‘[email protected]‘)) <AsyncResult: e3b50542-d643-4b4c-bd71-5fb11d7915b7> >>> sendmail.delay(dict(to=‘[email protected]‘)) <AsyncResult: ee225dd3-dea5-4013-907d-3dca5089c669> >>> sendmail.delay(dict(to=‘[email protected]‘)) <AsyncResult: e13d9de4-cd71-4aef-bc2c-bc4cc7dc3002> >>> sendmail.delay(dict(to=‘[email protected]‘)) <AsyncResult: 75a8c645-237c-4b64-831f-37936f71191f> >>>
# tasks.py import time from celery import Celery celery = Celery(‘tasks‘, broker=‘redis://localhost:6379/0‘) @celery.task def sendmail(mail): print(‘....sending mail to %s...‘ % mail[‘to‘]) time.sleep(20.0) print(‘mail sent.‘) ~
以上是关于分布式异步任务Celery的主要内容,如果未能解决你的问题,请参考以下文章