首页 > 解决方案 > 如何将多个参数传递给 Azure 持久活动函数

问题描述

我的协调器接收到一个有效负载,该有效负载包含需要与其他数据集一起传递给活动函数的指令。

如何将多个参数传递给活动函数?还是我必须将所有数据混合在一起?

def orchestrator_function(context: df.DurableOrchestrationContext):
    
    # User defined configuration
    instructions: str = context.get_input()

    task_batch = yield context.call_activity("get_tasks", None)
    
    # Need to pass in instructions too
    parallel_tasks = [context.call_activity("perform_task", task) for task in task_batch]

    results = yield context.task_all(parallel_tasks)
    
    return results

perform_task活动需要来自的项目和task_batch用户输入instructions

我在我的 中做某事function.json吗?

解决方法 不理想,但我可以将多个参数作为单个元组传递

something = yield context.call_activity("activity", ("param_1", "param_2"))

然后我只需要在活动中引用正确的参数索引。

标签: pythonazure-functionsazure-durable-functions

解决方案


似乎没有教科书的方法可以做到这一点。我选择给我的单个参数一个通用名称,例如parameteror payload

然后在编排器中传递值时,我会这样做:

payload = {"value_1": some_var, "value_2": another_var}
something = yield context.call_activity("activity", payload)

然后在活动功能中,我再次解压它。

编辑:一些隐藏的文档似乎表明https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-error-handling?tabs=python


推荐阅读