@Anil Bhat
To stop the execution of the orchestrations, you can use the TerminateAsync
method provided by the IDurableOrchestrationClient
interface. This method allows you to terminate a running orchestration instance. Here's an example of how you can use it:
[FunctionName("TerminateOrchestration")]
public static async Task<IActionResult> TerminateOrchestration(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
[DurableClient] IDurableOrchestrationClient client,
ILogger log)
{
string instanceId = req.Query["instanceId"];
string reason = req.Query["reason"];
await client.TerminateAsync(instanceId, reason);
return new OkResult();
}
You can call this function with the instance ID of the orchestration you want to terminate and a reason for the termination.
To set the number of retries of the orchestrations to 0, you can configure the retry policy for the orchestrator function. By default, orchestrator functions do not retry on failure. However, if you have configured a retry policy, you can set the maximum number of attempts to 1 to effectively disable retries. Here's an example of how you can configure the retry policy:
var retryOptions = new RetryOptions(
firstRetryInterval: TimeSpan.FromSeconds(5),
maxNumberOfAttempts: 1 // Set to 1 to disable retries
);
await context.CallActivityWithRetryAsync("ActivityFunctionName", retryOptions, input);
This will ensure that the orchestrator function does not retry on failure.
I hope this helps. Let me know if you have any other questions.
See:
- https://github.com/Azure/azure-functions-durable-extension/discussions/2029
- https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-instance-management?tabs=csharp
- https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-orchestrations?tabs=csharp-inproc
- https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-sub-orchestrations?tabs=csharp-inproc