Created
June 6, 2013 18:40
-
-
Save ionelmc/5723863 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Run: | |
python xeon.py worker -Q q0 | |
python xeon.py worker -Q q1 | |
python xeon.py worker -Q q2 | |
python xeon.py worker | |
python xeon.py produce-test | |
""" | |
import sys | |
import time | |
from celery import Celery | |
from celery.canvas import group | |
from kombu import Queue, Exchange | |
celery = Celery( | |
broker="amqp://test:test@localhost:5672/test" | |
) | |
celery.conf.update( | |
CELERY_RESULT_BACKEND="mongodb", | |
CELERYD_PREFETCH_MULTIPLIER=1, | |
) | |
@celery.task | |
def work(arg): | |
print '-> task_a(%s)' % arg | |
time.sleep(1) | |
print '<= task_a(%s)' % arg | |
return arg | |
if __name__ == '__main__': | |
if len(sys.argv) > 1 and sys.argv[1] == 'produce-test': | |
res = group([work.s(i).set(queue="q%s"%i) for i in range(3)]).apply_async() | |
print 'STARTED:', res | |
print 'DONE:', res.get() | |
else: | |
celery.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment