0

I have successfully managed to setup an Azure Durable function and I can execute it and see the http trigger activates, evidenced by the log files. I can also see the orchestrator_trigger being called.

I have setup the configuration settings to enable the v2 programming model:

AzureWebJobsFeatureFlags=EnableWorkerIndexing

As per the instructions here Here's the code

import json
import logging
from typing import Any
import azure.functions as func
import azure.durable_functions as df

myapp = df.Blueprint(http_auth_level=func.AuthLevel.ANONYMOUS)

@myapp.route(route="synthetic/solar/snapshot")
@myapp.durable_client_input(client_name="client")
async def http_start(req: func.HttpRequest, client):
    function_name = 'my_orchestrator_function'
    instance_id = await client.start_new(function_name)
    response = client.create_check_status_response(req, instance_id)
    return response

@myapp.orchestration_trigger(context_name="context")
def my_orchestrator_function(context):
    
    test_act_data = {"testdata": "test"}
    test_serialised_act_data = json.dumps(test_act_data)
    logging.info(f"Activity result: {test_serialised_act_data}")
    test_result = yield context.call_activity("hello_activity", test_serialised_act_data)
    return test_result

@myapp.activity_trigger(input_name="test_json")
def hello_activity(test_json: str):
    json_activity_data = json.loads(test_json)
    data = json_activity_data["testdata"] 
    logging.info("Hello Test, Executing Activity Trigger")
    return data

My host.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

And function_app.py:

import azure.functions as func 

app = func.FunctionApp() 

app.register_functions(myapp) 

I've tried improving the logging. I've tried to step through the stages and refer to lots of examples, but there's really no hint as to why the activity_trigger isn't being triggered.

http trigger log orchestrator log

1 Answer 1

1

Azure Durable Function using Python Programming Model V2 not calling activity_trigger

To call durable functions activity trigger use below code:

function_app.py:

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

myApp = df.DFApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@myApp.route(route="orchestrators/{functionName}")
@myApp.durable_client_input(client_name="client")
async def http_start(req: func.HttpRequest, client):
    function_name = req.route_params.get('functionName')
    instance_id = await client.start_new(function_name)
    response = client.create_check_status_response(req, instance_id)
    return response

@myApp.orchestration_trigger(context_name="context")
def rith_orchestrator(context):
    
    rith_act_data = {"testdata": "Rithwik"}
    rith_serialised_act_data = json.dumps(rith_act_data)
    logging.info(f"Activity result: {rith_serialised_act_data}")
    rith_result = yield context.call_activity("hello_rithwik", rith_serialised_act_data)
    return rith_result

@myApp.activity_trigger(input_name="rithjson")
def hello_rithwik(rithjson: str):
    json_activity_data = json.loads(rithjson)
    data = json_activity_data["testdata"] 
    logging.info("Helo Rithwik, Executing Activity Trigger")
    return data

requirements.txt

azure-functions
azure-functions-durable

host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=rithwik;AccountKey=pPBW9jWu77Sqp5F+NLWkA==;EndpointSuffix=core.windows.net",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
  }
}

Call a Function:

enter image description here

In URL replace functionName with Orchestrator Name as below:

http://localhost:7071/api/orchestrators/rith_orchestrator

Output:

enter image description here

Now use the first URL statusQueryGetUri , You will get serialized data:

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your response. I've gone through this carefully line by line. The only difference I can see is that you are returning the check_status_response URLs in the httpTrigger function. And then you are using the function statusQueryGetUri to get the status. But I assume it is not the querying of the Uri that triggers the execution of the activity_trigger? Please confirm.
It is calling then only you are getting Output as rithwik after serilaizing. Try to use my full code and change according to your requirement as mine is correct. Try using mine then it will work, there might be minute change which you may not be getting
That fixed my problem by slowly reapplying my changes. For the life of me I still don't understand exactly what the root cause was. The 2 lines I never added back in were: # @myApp.function_name(name="usage_synthetic_snapshot_post") # @myApp.route(route="orchestrators/{functionName}",auth_level=func.AuthLevel.ANONYMOUS, methods=["POST"]) I assume one of these 2 was causing the issue.
I have tried to now change the function name from hello_rithwik to my own function name in the 2 places its defined, but when I do that Azure hides the activity_trigger. There must be something that is being retained in the Azure function profile or something when you just change the function name. Because this should just work. Any ideas how to force a refresh of the function being processed and why it would do this? @rithwikbojja
Try to do this in Vs code and then later redploy it. Actually it should work when the name changed, maybe there might be cache issue in your environment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.