[英]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.