Title:
How to Perform an HTTP Response in Azure Durable Functions?
Content:
I would like to do an HTTP response with Azure's durable functions and display the results of the activity function on the site.
Environment and Assumptions
- Azure Free Tier
- Python Programming Model v2
- VSCode
I am considering executing the activity function of the Durable Functions in the above environment and having the client function receive the result and display it on the site via HTTP response.
Workflow
- client function receives HTTP request and its parameters
- the orchestrator function is invoked, and the parameters invoke the activity function
- The activity function processes the request and returns the result to the orchestrator function
- The orchestrator function returns the result to the client function
- display the result of the activity function on the site
Issue/Error Message
While attempting to retrieve the result of an activity function within the orchestrator function using call_activity() in Azure Durable Functions, I encountered the following error:
Exception: TypeError: Object of type AtomicTask is not JSON serializable
This issue prevents me from passing the activity function's result to the client function and subsequently displaying it via an HTTP response.
Source Code (Simplified Version)
Providing a simplified version of the source code, excluding exception handling:
Python Programming Model v2
#####################
## client_function ##
#####################
@app.route(route="orchestrators/client_function")
@app.durable_client_input(client_name="client")
async def client_function(req: func.HttpRequest, client: df.DurableOrchestrationClient) -> func.HttpResponse:
# Get parameters from HTTP request
process = req.params.get("process")
if process is None:
try:
process = req.get_json().get('process')
except (ValueError, KeyError):
process = 0
process = int(process)
instance_id = await client.start_new("orchestrator", None, {"process": process,})
logging.info(f"Started orchestration with ID = '{instance_id}'.")
# Wait for orchestration to complete
await client.wait_for_completion_or_create_check_status_response(req, instance_id)
# Get orchestration execution status
status = await client.get_status(instance_id)
# Retrieves orchestration execution results and displays them on the screen
runtime = status.runtime_status
output = status.output
return f"runtime: {runtime}\n\n output:{output}"
###########################
## orchestrator function ##
###########################
@app.orchestration_trigger(context_name="context")
def orchestrator(context: df.DurableOrchestrationContext) -> str:
parameters = context.get_input()
process = parameters.get("process")
result = None
if process == 0:
result = context.call_activity("failed")
else:
result = "Executed successfully. Pass a char and string in the query or in the request body."
context.set_custom_status(result)
return result
#######################
## activity_function ##
#######################
@app.activity_trigger
def failed() -> str:
return "failed_function executed successfully."
What I've Tried
I've attempted various methods to retrieve the activity function's result in the client function:
- Using set_custom_status() to transmit information from the orchestrator function to the client function.
- Employing client.wait_for_completion_or_create_check_status_response(req, instance_id) to obtain information from the orchestrator function in the client function.
Despite trying these approaches, I have been unable to identify the correct method.