0

I have below code of Orchestration function init.py

import logging
import json

import azure.functions as func
import azure.durable_functions as df


def orchestrator_function(context: df.DurableOrchestrationContext):
    input_context = context.get_input()
    requestBody = input_context.get('query')
    parallel_tasks = [  context.call_activity("db", requestBody) , context.call_activity("storage",requestBody)]
    status = { 'status' : "started"}
    context.set_custom_status(status)
    outputs =  context.task_all(parallel_tasks)
   
    #Set Custome Status
    status = { 'status' : "completed"}
    context.set_custom_status(status)
    return [outputs]

main = df.Orchestrator.create(orchestrator_function)

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "context",
      "type": "orchestrationTrigger",
      "direction": "in"
    }
  ]
}

how to get status or set async call to the activity trigger until the complete and get the status by every 5 seconds.

microset
  • 276
  • 1
  • 2
  • 12

1 Answers1

0

You can get the status of the orchestrator and its activity functions from the statusQueryGetUri field. The statusQueryGetUri is obtained as a response from the orchestrator or starter function url. The following is the orchestrator url

http://functionappname/api/orchestrators/Orchestratorname

The statusQueryGetUri contains a url that provides the status of orchestrator and its associated activity function.

Below is the response from my starter function

{
"id":"f407f4bbb058486da0c2db08efeecd53",
"statusQueryGetUri":"http://localhost:7188/runtime/webhooks/durabletask/instances/f407f4bbb058486da0c2db08efeecd53?taskHub=TestHubName&connection=Storage&code=4pUMMzR9AWXfSFkJJUzUwJ4XVpQ7LkEULqBy-jiChGDKAzFuldf_dA=="

If I launch the statusQueryGetUri in the browser, I would get the below response

{
"name":"Function1",
"instanceId":"f407f4bbb058486da0c2db08efeecd53",
"runtimeStatus":"Completed",
"input":null,
"customStatus":null,
"output":["Hello Tokyo!","Hello Seattle!","Hello London!"],
"createdTime":"2022-12-07T10:12:18Z",
"lastUpdatedTime":"2022-12-07T10:12:20Z"
}

Reference: https://learn.microsoft.com/en-us/azure/azure-functions/durable/quickstart-python-vscode?tabs=linux#test-the-function-locally

The statusQueryGetUri url can be called every 5 seconds from your code using the requests module in python. Please refer to the below article to call a function every 5 seconds

How to repeatedly execute a function every x seconds?