![](/img/trans.png)
[英]How to get status of HTTP activity from azure durable orchestrator function on every 5 seconds in Python?
[英]How to pass multiple parameters to Azure Durable Activity Function
我的协调器接收到一个有效负载,该有效负载包含需要与其他数据集一起传递给活动函数的指令。
如何将多个参数传递给活动 function? 还是我必须将所有数据混合在一起?
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"))
然后我只需要在活动中引用正确的参数索引。
似乎没有教科书的方法来做到这一点。 我选择给我的单个参数一个通用名称,如parameter
或payload
。
然后在编排器中传递值时,我会这样做:
payload = {"value_1": some_var, "value_2": another_var}
something = yield context.call_activity("activity", payload)
然后在活动 function 中,我再次打开包装。
编辑:一些隐藏的文档似乎表明https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-error-handling?tabs=python
只是为了添加到@Ari 的好答案,这里的代码将数据从客户端 function(在这种情况下为 HTTP 请求)一直传递到活动 function:
Client -> Orchestrator -> Activity
客户
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
client = df.DurableOrchestrationClient(starter)
req_data = req.get_json()
img_url = req_data['img_url']
payload = {"img_url": img_url}
instance_id = await client.start_new(req.route_params["functionName"], None, payload)
logging.info(f"Started orchestration with ID = '{instance_id}'.")
return client.create_check_status_response(req, instance_id)
编排器
def orchestrator_function(context: df.DurableOrchestrationContext):
input_context = context.get_input()
img_url = input_context.get('img_url')
some_response= yield context.call_activity('MyActivity', img_url)
return [some_response]
活动
def main(imgUrl: str) -> str:
print(f'.... Image URL = {imgUrl}')
return imgUrl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.