'Is there a way to prevent start of a durable azure function?

I have an Azure Durable function (.NET 6) triggered with httpTrigger, I'm trying to prevent start of the function based on the parameters received in the http request.

The code I tried so far :

 [FunctionName(nameof(StartOrchestrator))]
    public async Task<HttpResponseMessage> StartOrchestrator(
        [HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestMessage req,
        [DurableClient] IDurableOrchestrationClient starter)
    {
        var stringContent = await req.Content.ReadAsStringAsync();
        var parameter = GetParam(stringContent);
        if (string.IsNullOrEmpty(filter.MyParam))
        {
            //Here I want to prevent start of the orchestration with a 400 bad request error
            return req.CreateErrorResponse(HttpStatusCode.BadRequest, "Request doesn't contains MyParam");
        }
        var instanceId = await starter.StartNewAsync(nameof(RunOrchestrator), parameter);
        return starter.CreateCheckStatusResponse(req, instanceId);
    }

The result I'm getting :

enter image description here

Is there a way to do what I'm trying to ?



Solution 1:[1]

It should be a semaphore issue, two threads are created right here and azure functions doesn't support synchronouse operations so this is where the 500 is coming from. The solution is to set the variable FUNCTIONS_V2_COMPATIBILITY_MODE enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bechir Anoir Chabchoub