0

I have a project with an Azure function that have two http triggers functions.

import azure.functions as func
from func_utils.main_func import http_trigger_function
from func_utils.get_data_trigger import main_second_trigger_func


#Instantiate the HTTP Function app 
app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)

@app.route(route="http_trigger_function")
def http_trigger_func(req: func.HttpRequest, context) -> func.HttpResponse: 

    return http_trigger_function(req, context)


# Segundo HTTP Trigger
@app.route(route="get-data")
def main_second_trigger(req: func.HttpRequest) -> func.HttpResponse:

    return main_second_trigger_func(req)

I want to use durable functions and do something like this:

def http_trigger(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    """HTTP trigger to start the orchestration."""
    client = df.DurableOrchestrationClient(starter)
    order_details = req.get_json()

    # Start the orchestration
    instance_id = client.start_new("orchestrator_function", None, order_details)

    return func.HttpResponse(f"Orchestration started with ID = {instance_id}")

I just declared the starter in my function like that example, without use the starter in this moment just to see how it works. But i am having this error when tried to start the function:

Worker failed to index functions
[2024-11-28T23:08:32.196Z] Result: Failure
Exception: FunctionLoadError: cannot load the http_trigger_func function: the following parameters are declared in Python but not in function.json: {'starter'}     
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 413, in _handle__functions_metadata_request
    self.load_function_metadata(
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 393, in load_function_metadata
    self.index_functions(function_path, function_app_directory)) \
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 773, in index_functions   
    loader.process_indexed_function(
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\loader.py", line 139, in process_indexed_function
    function_info = functions_registry.add_indexed_function(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\functions.py", line 450, in add_indexed_function
    deferred_bindings_enabled) = self.validate_function_params(
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11\WINDOWS\X64\azure_functions_worker\functions.py", line 137, in validate_function_params
    raise FunctionLoadError(

This is my host.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.*, 4.0.0)"
  },
  "extensions": {
    "http": {
      "routePrefix": "api",
      "hsts": {
        "isEnabled": true,
        "includeSubDomains": true,
        "maxAge": "365"
      },
      "customHeaders": {
        "X-Content-Type-Options": "nosniff",
        "X-Frame-Options": "DENY",
        "X-XSS-Protection": "1; mode=block",
        "Content-Security-Policy": "default-src 'self'",
        "X-Content-Security-Policy": "default-src 'self'"
      }
    },
    "durableTask": {
      "hubName": "DurableFunctionsHub",
      "maxConcurrentActivityFunctions": 10,
      "maxConcurrentOrchestratorFunctions": 10
      }
  }
}


I don't have a function.json

I have tried to declare the starter as follows:

starter: df.DurableOrchestrationClient

But it doesn't work

1
  • Are you trying locally? Commented Nov 30, 2024 at 13:39

1 Answer 1

0

To start the durable function you do not need a starter but you can use function name from parameter while passing through URL and followed My SO-Answer:

import azure.functions as ric
import logging
import json
import azure.durable_functions as ch

rithapp=ch.DFApp(http_auth_level=ric.AuthLevel.ANONYMOUS)
@rithapp.route(route="http_trigger")
def http_trigger(req: ric.HttpRequest) -> ric.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    return ric.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )

@rithapp.route(route="orchestrators/{functionName}")
@rithapp.durable_client_input(client_name="client")
async def http_start(req: ric.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

@rithapp.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

@rithapp.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

So, to call orchestrator use:

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

This is the format of durable function, you can call orchestrator from http start and then call the activity trigger. So you have to have orchestrator also.

Output:

enter image description here

Calling http_start:

enter image description here

I don't have a function.json

You do not have function.json, when you are creating azure function locally and Structure of it according to Microsoft-Document will be:

<Rth Folder>/
 | - .venv/
 | - .vscode/
 | - function_app.py
 | - extra_rith_funs.py
 | - tests/
 | | - test_rith_func.py
 | - .funcignore
 | - host.json
 | - local.settings.json
 | - requirements.txt
 | - Dockerfile
Sign up to request clarification or add additional context in comments.

Comments

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.