Wednesday, February 26, 2014

New user notes on using Celery with python

I'm a totally new user using Celery in python. Here are my notes:

My celery_test.py file:
 
from celery import Celery
import time
app = Celery('tasks', broker='amqp://guest@localhost//')
@app.task
def add(x, y):
    time.sleep(5)
    return x + y



celery -A celery_test worker --loglevel=info
A command like this at the terminal reads the stuff in celery_test.py where you have @app.task decorators on functions. The server will then run the function when you do this from any python intepreter:

>>> from celery_test import *
>>> add.delay(100, 200)

By the way:After modifying the add function, I had to update Celery by killing this process and running it again:
celery -A celery_test worker --loglevel=info

No comments: