CodexBloom - Programming Q&A Platform

How to implement Azure Function with Durable Functions for orchestrating long-running workflows?

👀 Views: 78 💬 Answers: 1 📅 Created: 2025-06-09
Azure Functions Durable Functions Orchestration C#

I'm trying to implement an Azure Function that uses Durable Functions to orchestrate a long-running workflow, but I'm running into issues when attempting to manage state across function executions. My function is supposed to call an external API, wait for a response, and then trigger another function to process that response. However, I keep working with the following behavior: `DurableFunctionTimeoutException: The function execution exceeded the allowed timeout of 00:05:00 seconds.` Here’s the code I have for the orchestration function: ```csharp [FunctionName("OrchestratorFunction")] public static async Task RunOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context) { var result = await context.CallActivityAsync<string>("CallExternalApi", null); await context.CallActivityAsync("ProcessApiResponse", result); } ``` In addition, here’s the activity function that calls the external API: ```csharp [FunctionName("CallExternalApi")] public static async Task<string> CallExternalApi([ActivityTrigger] string name, ILogger log) { // Simulating a long-running API call await Task.Delay(600000); // 10 minutes delay return "response"; } ``` I'm aware that Durable Functions have a maximum timeout for orchestrations, and that the recommended practice is to keep the orchestration function lightweight. I’ve tried to implement a pattern where I use `Task.Delay` and call the activity function multiple times, but it seems to still exceed the timeout limit. What’s the correct approach to handle long-running workflows with Durable Functions without running into timeout issues? Should I be refactoring my logic to break the orchestration into smaller parts, or is there a method to extend the timeout sufficiently for my use case? Any insights on best practices would be greatly appreciated.