我有 3 個 Azure Functions 正在嘗試編排。由于某種原因,活動功能沒有被呼叫。
流程如下
F1 (Service Bus) -> F2 (Orchestrator) -> F3 (Activity)
F1
這是服務總線訊息呼叫的函式。這作業正常。
import logging
import json
import azure.functions as func
import azure.durable_functions as df
async def main(msg: func.ServiceBusMessage, starter: str):
client = df.DurableOrchestrationClient(starter)
json_body = json.loads(msg.get_body().decode('utf-8'))
instance_id = await client.start_new('F2', None, json_body)
logging.info(f"Started orchestration with ID = '{instance_id}'")
配置是
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "msg",
"type": "serviceBusTrigger",
"direction": "in",
"queueName": "queueN",
"connection": "processConnectionString"
},
{
"name": "starter",
"type": "durableClient",
"direction": "in"
}
]
}
F2
這是協調器功能,也會被呼叫;但是執行就Awaited在眼前result = yield context.call_activity('F3', input_json)
import logging
import json
import azure.functions as func
import azure.durable_functions as df
def orchestrator_function(context: df.DurableOrchestrationContext):
input_json = context.get_input()
result = yield context.call_activity('F3', input_json)
return result
main = df.Orchestrator.create(orchestrator_function)
配置是,
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "context",
"type": "orchestrationTrigger",
"direction": "in"
}
]
}
F3
應執行活動的最終功能。這不是從F2
import logging
def main(input_json) -> str:
logging.info('Input processed message : %s', input_json)
return "Hello!"
配置是,
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "input_json",
"type": "activityTrigger",
"direction": "in"
}
]
}
使用 Azure Function4運行時和 Python 3.7(由于遺留原因)。更新:嘗試使用 Python3.9也不起作用
xxxxxx: Function 'F2 (Orchestrator)' awaited. IsReplay: False. State: Awaited. HubName: pyproxxxxx. AppName: py-proxxxxx. SlotName: Production. ExtensionVersion: 2.8.1. SequenceNumber: 11.
可能是什么問題?
uj5u.com熱心網友回復:
當我嘗試運行此代碼時,我在終端閱讀時收到警告
[2022-11-07T20:56:23.947Z] The 'F3' function is in error: The binding name input_json is invalid. Please assign a valid name to the binding.
所以我認為問題在于引數名稱input_json不是 Azure Functions 中的有效識別符號。我通過重命名input_json來讓它作業inputJson(即把snake_case變成camelCase)。
所以這一切都讓我懷疑問題是 Azure Functions 運行時沒有正確決議蛇形大小寫,我認為這對于 Python 開發人員來說不是慣用的。我會將這個反饋傳遞給 Python 團隊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/528889.html
