1. 程式人生 > >celery broker和backend對接rabbitmq和redis

celery broker和backend對接rabbitmq和redis

result.ready()

可能一直返回False

把redis重啟

 

127.0.0.1:6379> flushall                         

//刪除當前資料庫中的所有Key
flushdb
//刪除所有資料庫中的key
flushall

(venv3) [[email protected] mcelery]# ls
__pycache__  tasksbk.py  tasks.py
(venv3) [

[email protected] mcelery]# 

[[email protected] mcelery]# celery -A tasks worker --loglevel=info --pool=solo

 

 

#coding=utf-8
from celery import Celery

#broker = 'redis://127.0.0.1:6379/7'
broker = 'amqp://guest:[email protected]:5672/'
backend = 'redis://127.0.0.1:6379/8'

app = Celery('tasks', broker=broker, backend=backend)

@app.task
def add(x, y):
    return x + y
(venv3) [[email protected] mcelery]# python 
Python 3.6.4 (default, Nov 22 2018, 08:20:15) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more informtion.
>>> from tasks import add
>>> r = add.delay(34,23)
>>> r.status
'PENDING'
>>> r.ready()
False
>>> r.ready()
False
>>> r.ready()
True
>>> r.ready()
True
>>> r.status
'SUCCESS'
>>> 

參考:https://www.cnblogs.com/cwp-bg/p/8759638.html

http://docs.jinkan.org/docs/celery/getting-started/index.html

https://www.jianshu.com/p/1840035cb510

[email protected]:JackLiu16/mcelery.git