Answer a question

My orchestrator receives a payload, with that payload it contains instructions that need to be passed along with other sets of data to activity functions.

how do I pass multiple parameters to an activity function? Or do I have to mash all my data together?

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

The perform_task activity needs both the items from task_batch and the user input instructions

Do I do something in my function.json?

Workaround Not ideal, but I can pass multiple parameters as a single Tuple

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

I then just need to reference the correct index of the parameter in the activity.

Answers

Seems there's no text-book way to do it. I have opted to give my single parameter a generic name like parameter or payload.

Then when passing in the value in the orchestrator I do it like so:

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

then within the activity function, I unpack it again.

edit: Some buried documentation seems to show that https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-error-handling?tabs=python

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐