| 1 |
"""myapp.py |
| 2 |
|
| 3 |
Usage:: |
| 4 |
|
| 5 |
(window1)$ python myapp.py worker -l INFO |
| 6 |
|
| 7 |
(window2)$ python |
| 8 |
>>> from myapp import add |
| 9 |
>>> add.delay(16, 16).get() |
| 10 |
32 |
| 11 |
|
| 12 |
|
| 13 |
You can also specify the app to use with the `celery` command, |
| 14 |
using the `-A` / `--app` option:: |
| 15 |
|
| 16 |
$ celery -A myapp worker -l INFO |
| 17 |
|
| 18 |
With the `-A myproj` argument the program will search for an app |
| 19 |
instance in the module ``myproj``. You can also specify an explicit |
| 20 |
name using the fully qualified form:: |
| 21 |
|
| 22 |
$ celery -A myapp:app worker -l INFO |
| 23 |
|
| 24 |
""" |
| 25 |
from time import sleep |
| 26 |
|
| 27 |
from celery import Celery |
| 28 |
|
| 29 |
app = Celery( |
| 30 |
'myapp', |
| 31 |
broker='amqp://guest@localhost//', |
| 32 |
# ## add result backend here if needed. |
| 33 |
# backend='rpc' |
| 34 |
task_acks_late=True |
| 35 |
) |
| 36 |
|
| 37 |
|
| 38 |
@app.task |
| 39 |
def add(x, y): |
| 40 |
sleep(10) |
| 41 |
return x + y |
| 42 |
|
| 43 |
|
| 44 |
if __name__ == '__main__': |
| 45 |
app.start() |