How to terminate Azure orchestration function instance via API? Other ways to Terminate?

Matthew Villarreal 0 Reputation points
2023-10-20T16:48:28.15+00:00

I have a Durable functions application that is in the cloud and failed on one of its activity functions so the Orchestrator has been in a running state. I attempted to terminate via https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-http-api#terminate-instance terminate suggestion provided by MS. But I am only getting 404 not found. Is there any way I can do this via API or manually stop the run? I have tried doing the async terminate HTTP trigger option and same issue, nothing but errors. Is there another way to terminate possibly in Azure Portal?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,936 questions
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 27,550 Reputation points Microsoft Employee Moderator
    2023-10-23T07:40:54.87+00:00

    @Matthew Villarreal Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    I see that you are having trouble terminating an Azure orchestration function instance via API and is receiving a 404 error. You are looking for alternative ways to terminate the instance.

    I am sharing 2 more ways how you can terminate the Durable Function instance:

    Approach 1:

    If you have an orchestration instance that is taking too long to run, or you just need to stop it before it completes for any reason, you can terminate it.

    The two parameters for the terminate API are an instance ID and a reason string, which are written to logs and to the instance status.

    [FunctionName("TerminateInstance")]
    public static Task Run(
        [DurableClient] IDurableOrchestrationClient client,
        [QueueTrigger("terminate-queue")] string instanceId)
    {
        string reason = "Found a bug";
        return client.TerminateAsync(instanceId, reason);
    }
    

    A terminated instance will eventually transition into the Terminated state. However, this transition will not happen immediately. Rather, the terminate operation will be queued in the task hub along with other operations for that instance. You can use the instance query APIs to know when a terminated instance has actually reached the Terminated state.

    Approach 2:
    You can also terminate an orchestration instance directly, by using the func durable terminate command in Core Tools.

    The durable terminate command takes the following parameters:

    • id (required): ID of the orchestration instance to terminate.
    • reason (optional): Reason for termination.
    • connection-string-setting (optional): Name of the application setting containing the storage connection string to use. The default is AzureWebJobsStorage.
    • task-hub-name (optional): Name of the Durable Functions task hub to use. The default is DurableFunctionsHub. It can also be set in host.json, by using durableTask:HubName.

    The following command terminates an orchestration instance with an ID of 0ab8c55a66644d68a3a8b220b12d209c:

    func durable terminate --id 0ab8c55a66644d68a3a8b220b12d209c --reason "Found a bug"

    Fore more information, please refer this article.

    Hope this helps.

    **
    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.