コード例 #1
0
# from test_nfs_task import TestNfsTask

test ="amqp://*****:*****@172.16.4.134:5672/cabbage_vhost"
app = Celery('cabbage',broker=test)
app.config_from_object("cabbage.cabbage_celery.celeryconfig")
# import celeryconfig
# app.config_from_object(celeryconfig)


for k,v in app.conf.items():
    print k,v
app.conf.update(CELERY_ROUTES = {     
                 'test_ic_task.TestIcTask': {'queue': 'test2', 'routing_key': 'test2'},     
#                  'product_list_crawler.ProductListCrawlerTask': {'queue': 'celery', 'routing_key': 'celery'}
                  })
# taskId = "de1d0b16-57b1-4128-87bc-3697f78ab6dc"

state = app.events.State()
print app.tasks()

# print state.tasks.get(taskId)

app.send_task("test_ic_task.TestIcTask",kwargs={"jobId"})

res =AsyncResult(taskId)
print res._get_task_meta()
print res.ready()
print res.result
print dir(res)
print res.task_name
コード例 #2
0
app.conf.update(
    CELERY_ROUTES={
        'test_nfs_task.TestNfsTask': {
            'queue': 'test',
            'routing_key': 'test'
        },
        #                  'product_list_crawler.ProductListCrawlerTask': {'queue': 'celery', 'routing_key': 'celery'}
    })
# app.conf.update(CELERY_QUEUES=( Queue('hdfs', Exchange('hdfs'), routing_key='hdfs'),))
# print app.conf["CELERY_RESULT_BACKEND"]
results = []
for i in range(10000):
    print i
    result = app.send_task("test_nfs_task.TestNfsTask",
                           kwargs={
                               "jobId":
                               "job-a986d7d9-4950-4c45-a3c5-6553d81d5a36",
                               "no": i
                           })
    results.append(result)

time.sleep(10)
#     from celery.task.control import inspect
#     i = inspect()
#     print i.scheduled()
#     print i.active()
# for result in results:
# #         print result.backend
# #         print result.get()
#     print result
#     print result.status
#     print result.result
コード例 #3
0
    u'test_mac_task.TestMacTask': {
        'queue': 'huawei',
        'routing_key': 'huawei'
    }
}

app = Celery(
    'cabbage',
    broker=
    'amqp://*****:*****@172.16.4.134:5672/cabbage_vhost')
app.config_from_object("cabbage.cabbage_celery.celeryconfig")
app.conf.update(CELERY_ROUTES=routes)

app.send_task("test_ubuntu_task.TestUbuntuTask",
              kwargs={
                  "jobId": "job-a986d7d9-4950-4c45-a3c5-6553d81d5a36",
                  "no": 2
              })

origRoutes = app.conf["CELERY_ROUTES"]
print app.tasks
print "CELERY_ROUTES:[%s]" % app.conf["CELERY_ROUTES"]

origRoutes.update(mac_routes)
print origRoutes
print "-------------------------------------------------"

app.conf.update(CELERY_ROUTES=origRoutes)

app.send_task("test_mac_task.TestMacTask",
              kwargs={
コード例 #4
0
# -*- encoding: utf-8 -*-
'''
Created on 2016年8月10日

@author: hua
'''
from celery.app.base import Celery

app = Celery(
    'cabbage',
    backend="rpc://",
    broker='amqp://*****:*****@10.0.137.88:5672/cabbage_vhost'
)

for i in range(1):
    result = app.send_task("product_list_crawler.ProductListCrawlerTask",
                           kwargs={'lid': 1})
    print result

# print "start job"
# i = app.control.inspect()
# result = i.stats()
# print result
# print i.registered_tasks()
コード例 #5
0
ファイル: test_task.py プロジェクト: xtuyaowu/cabbage-celery
    argv = ['--pool=threads']
    app.worker_main(argv)


class Test():
    def run(self):
        for i in range(100):
            #             result = T.run.delay()
            result2 = T.run2.delay(4, 5, i)
            #             result2 = T.run2.delay(4, 5)
            print "result2:" + str(result2)
            while (1):
                if result2.ready():
                    print result2.result
                    break
                time.sleep(2)
                print result2.status


#         print ITask.implementedBy(T)

if __name__ == "__main__":
    for i in range(100):
        result = app.send_task("test_task.TestTask", args=(1, 2))
        print result.get()
#     t1 = threading.Thread(target=run)
#     t1.setDaemon(True)
#     t1.start()
#     time.sleep(5)
#     Test().run()