ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

celery:不同msg的dispatch_logic所对应的参数修改方法比较

2022-07-27 21:04:54  阅读:171  来源: 互联网

标签:info content name schedule list dispatch celery logic msg


【一】利用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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有