skip to Main Content

I’m facing an issue with my Azure Function App that’s triggered by a pipeline. Initially, my function app would always return a success code, even if one of its activities failed. To fix this, I modified the code to check the status of the activity and return a failure code if it failed.

Here’s the original code:

@myApp.route(route="orchestrators/xml_remit_gen", methods=["POST"])
@myApp.durable_client_input(client_name="client")
async def http_xml_remit_gen(req: func.HttpRequest, client: df.DurableOrchestrationClient):
    try:
        req_body = req.get_json()
        set_configurations(req_body, False)
        # Assuming no additional arguments are required for start_new
        instance_id = await client.start_new("xml_remit_gen_orchestrator", None, req_body)
        response = client.create_check_status_response(req, instance_id)
        return response
    except Exception as e:
        error_message = str(e)
        return func.HttpResponse(error_message, status_code=500)

And here’s the modified code:

@myApp.route(route="orchestrators/xml_remit_gen", methods=["POST"])
@myApp.durable_client_input(client_name="client")
async def http_xml_remit_gen(req: func.HttpRequest, client: df.DurableOrchestrationClient):
    try:
        req_body = req.get_json()
        set_configurations(req_body, False)
        # Assuming no additional arguments are required for start_new
        instance_id = await client.start_new("xml_remit_gen_orchestrator", None, req_body)
         while True:
                 status = await client.get_status(instance_id)
                 if status.runtime_status in [df.OrchestrationRuntimeStatus.Failed, df.OrchestrationRuntimeStatus.Completed]:
                     break  
                 await asyncio.sleep(1)  

         if status.runtime_status in [df.OrchestrationRuntimeStatus.Failed, 'Failed']:
             response = client.create_check_status_response(req, instance_id)
             return client._create_http_response(500, status.output)
            
        response = client.create_check_status_response(req, instance_id)
        return response
    except Exception as e:
        error_message = str(e)
        return func.HttpResponse(error_message, status_code=500)

However, after making this change, the pipeline is timing out automatically after 4 minutes. Initially i was facing this issue, which led me to consider using Azure Durable Functions, but I encountered same problem again. How can I resolve this timeout issue and ensure that the function app returns the appropriate success or failure code based on the activity’s status?

2

Answers


  1. You haven’t shared how the pipeline triggers your function. Let’s assume your function is triggered by pipeline resource usage check to Invoke Azure Function with Completion event as callback, when the pipeline requests to use the resource, the check operation will trigger your function and wait for the callback request sent back to Azure DevOps from your function. If the check doesn’t receive the callback request in a time limit configured in the Timeout settings in the Control options, the check will fail.

    Furthermore, I didn’t see any callback request sent back to Azure DevOps from your function, which should authenticate against AuthToken and specify taskId, jobId and result in the request body. Please check Asynchronous checks and update your function to call into Azure DevOps.

    enter image description here
    enter image description here

    Login or Signup to reply.
  2. How to call this durable functions and get the appropriate success or failure code based on the activity’s status from Azure data factory web activity using http based trigger (function app url)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search