- Install Celery and RabbitMQ on MAC:
pip install celery
brew install rabbitmq
-
Basic
Create folder celery_try and create file tasks.py. In this tasks.py, we define a Celery task:
app = Celery('tasks', backend="amqp", broker='amqp://guest@localhost:5672//')
backend is required if we want to extract results back. Then define a task:
@app.task
def add(x, y): print 'hello celery' time.sleep(10) return x + y
Then start our celery worker:
celery worker -A tasks --loglevel=INFO
And test if we are able to assign tasks to the worker:
$python
from tasks import add result = add.delay(3,5) result.ready() False result.state 'PENDING' result.state 'SUCCESS' result.ready() True result.get() 8