'''
Created on May 31, 2012

@author: liubida
'''

from celery.execute import send_task
from junior.celeryd.tasks import add
#from celery import task


#a = add(1, 2)
#print add.name
#numbers = [(x,x) for x in range(1,10)]
#results = []
#publisher = add.get_publisher()
#
#try:
#    for args in numbers:
#        ret = add.delay(arg=args, publisher=publisher)
#        results.append(ret)
#except Exception, e:
#    print e
#finally:
#    publisher.close()
#    publisher.connection.close()

'''
@note celeryd -l info
'''

numbers = [(2, 2), (4, 4), (8, 8), (16, 16)]

results = []
#publisher = add.get_publisher()
try:
    for i in range(10):
        for args in numbers:
            res = add.apply(*args)
            results.append(res)
finally:
    pass
#    publisher.close()
#    publisher.connection.close()

print ([res.get() for res in results])

#from celery.task.control import broadcast
#from celery.task.control import ping
#ret1 = ping(timeout=1)
#ret2 = ping(['w2.tc_6_173','w5.tc_6_175','liubida-desktop'])
#print ret1
#print ret2

#from celery.task.control import inspect
#i = inspect(["liubida-desktop"]) 
#print i.registered_tasks()
#print i.registered()
#print i.active()
#print i.scheduled()
#print i.reserved()

##result = send_task('celeryd.tasks.add', [2, 2])
#for i in range(20):
##    result = add.apply(i, i)
#    result = add.delay(i, i)
#    print result.task_id
#    while not result.ready():
#        time.sleep(0.2)
#        print '.',
#    print result.get()
#
##from celery import registry
##print registry.tasks


