celery:不同msg的dispatch_logic所对应的参数修改方法比较
作者:互联网
【一】利用celery对‘game_test_S1’和‘game_test_S2’两个服务器执行任务/需求:‘test’
#dispatch:dispatch_submit.py
def get_msg(): msg = 'game_test_S1,game_test_S2' schedule = dict() schedule['name'] = 'HELLO' schedule['instance'] = 'test' schedule['queue_name'] = 'celery_server' schedule['content'] = msg return str(schedule)
#dispatch:dispatch_logic.py
def rmq_rpc_call_back(msg): print '<rmq_rpc_call_back> msg:{}'.format(msg) info = eval(msg) name = info['name'] if name == 'HELLO': content = info['content'] content_list = content.split(',') instance_name = info['instance'] queue_name = info['queue_name'] param_list = [] for c in content_list: param_list.append({'content': c}) from instance.module.work_flow_logic.work_flow_methods import WorkFlowMethods from logic.celery_core.config.celery_config import CUSTOM_TASK_REGISTER_PATH sig = WorkFlowMethods.make_signature_batch(CUSTOM_TASK_REGISTER_PATH, instance_name, param_list, queue_name) res = sig.apply_async() print sig return res.id else: pass
content_list的内容是['game_test_S1','game_test_S2'] 是一个列表
param_list.append({'content':c})这里应用主键的目的是为了在‘test’中能引用‘key’ 这样就不用一个一个去输入msg啦
注意:涂色函数的parameter_list 参数是包含多个字典的list,即[{},{},{}] 也就是说
【二】利用celery对‘5#3’和‘6#4’执行任务/需求:‘power’
#dispatch:dispatch_submit.py
def get_msg(): msg = '5#3,6#4' schedule = dict() schedule['name'] = 'HELLO' schedule['instance'] = 'power' schedule['queue_name'] = 'celery_server' schedule['content'] = msg return str(schedule)
def rmq_rpc_call_back(msg): print '<rmq_rpc_call_back> msg:{}'.format(msg) info = eval(msg) name = info['name'] if name == 'HELLO': content = info['content'] content_list = content.split(',') instance_name = info['instance'] queue_name = info['queue_name'] param_list = [] param_list.append({'content': content_list[0], 'content_1': content_list[1]}) for c in content_list: c_list = c.split("#") param_list.append({'content': c}) from instance.module.work_flow_logic.work_flow_methods import WorkFlowMethods from logic.celery_core.config.celery_config import CUSTOM_TASK_REGISTER_PATH sig = WorkFlowMethods.make_signature_batch(CUSTOM_TASK_REGISTER_PATH, instance_name, param_list, queue_name) res = sig.apply_async() print sig return res.id else: pass
区别为绿字哦
标签:info,content,name,schedule,list,dispatch,celery,logic,msg 来源: https://www.cnblogs.com/bcattie-nicole/p/16526257.html