Skip to content

Instantly share code, notes, and snippets.

@ionelmc
Created June 6, 2013 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ionelmc/5723863 to your computer and use it in GitHub Desktop.
Save ionelmc/5723863 to your computer and use it in GitHub Desktop.
"""
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