【发布时间】:2022-01-03 18:43:49
【问题描述】:
我有 Azure 耐用功能。它主要基于: https://docs.microsoft.com/en-us/azure/azure-functions/durable/quickstart-python-vscode
我正在尝试将常规 HTTP 触发器迁移为持久函数?
我已修改代码以在 HTTP 启动和 Orchestrator 函数中接受 json。 但是活动函数不能接受 json。 如何修改 HelloActivity 以接受 json?以下行似乎会导致问题。
def main(datajson: str) -> str:
HelloOrchestrator:
import logging
import json
import azure.functions as func
import azure.durable_functions as df
def orchestrator_function(context: df.DurableOrchestrationContext):
# Take the json data from the DurableOrchestrationContext, which was passed during the invocation
data = context._input
data = json.loads(data)
logging.info(f"Orchestrator: Input is: {data}")
result1 = yield context.call_activity('HelloActivity', data)
#result1 = yield context.call_activity('HelloActivity', "ThisWouldWork")
return [result1]
main = df.Orchestrator.create(orchestrator_function)
HelloActivity
import logging
def main(datajson: str) -> str:
logging.info(f"Activity datajson :" + datajson)
return f"Hello world"
错误:
Function 'HelloOrchestrator (Orchestrator)' failed with an error. Reason: Message:
Activity function 'HelloActivity' failed: TypeError: can only concatenate str (not
"dict") to str
{"$type":"System.Exception,
System.Private.CoreLib","ClassName":"System.Exception","Message":" TypeError: can only
concatenate str (not \"dict\") to str","Data":null,"InnerException":{"$type":"Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException,
【问题讨论】:
-
您的错误在于这一行 logging.info(f"Orchestrator: Input is: {data}")。传递原始字符串 (context._input) 而不是 dictionary 对象。
标签: azure-functions azure-durable-functions