码迷,mamicode.com
首页 > 其他好文 > 详细

分布式异步任务Celery

时间:2018-04-15 13:35:30      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:led   default   任务   cte   info   more   ant   connected   main   

  

 

-A代表APP


celery -A tasks  worker --loglevel=info -n nodemaster
 
 -------------- celery@nodemaster 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] celery@nodemaster ready.




celery -A tasks  inspect registered

celery -A tasks inspect registered
-> celery@node2: OK
    * tasks.sendmail
-> celery@nodemaster: 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=‘celery@python.org‘))
<AsyncResult: b49534cd-472f-42da-934c-057e53e0d0a8>
>>> sendmail.delay(dict(to=‘celery@python.org‘))
<AsyncResult: 99cd7565-612a-4b31-b025-de7b5c48673c>
>>> sendmail.delay(dict(to=‘celery@python.org‘))
<AsyncResult: bd123165-d220-4552-bcb8-e009c76258d7>
>>> sendmail.delay(dict(to=‘celery@python.org‘))
<AsyncResult: 01a8ef22-149c-4b24-8d92-f07468598646>
>>> sendmail.delay(dict(to=‘celery@python.org‘))
<AsyncResult: e3b50542-d643-4b4c-bd71-5fb11d7915b7>
>>> sendmail.delay(dict(to=‘celery@python.org222222‘))
<AsyncResult: ee225dd3-dea5-4013-907d-3dca5089c669>
>>> sendmail.delay(dict(to=‘celery@python.org2222223‘))
<AsyncResult: e13d9de4-cd71-4aef-bc2c-bc4cc7dc3002>
>>> sendmail.delay(dict(to=‘celery@python.org2222227‘))
<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

标签:led   default   任务   cte   info   more   ant   connected   main   

原文地址:https://www.cnblogs.com/studyNT/p/8846810.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!