2

Is it OK to use Task.Delay inside an Azure Durable Function Activity like this?

I am polling storage for data that should arrive within 20-30 seconds or so.

 while (requestAccepted && retryCount < 8)
        {
            object savedData = await DataManagementService.GetSessionData(processSessionId);

            if (savedData != null && savedData.GetType().GetProperties().Any())
            {
                return true;
            }

            await Task.Delay(TimeSpan.FromSeconds(10));

            retryCount++;
        }

The function timers feature using context.CreateTimer, explained here, is only available to Azure Orchestration Function and not Activity Function.

puri
  • 1,829
  • 5
  • 23
  • 42

1 Answers1

2

It's perfectly OK to use Task.Delay() as long as you're happy paying for the dead time while the function's waiting and you know that it will complete before it times out.

However, a better option is to move the GetSessionData() call into an activity function, convert this polling function to an orchestrator so you can replace Task.Delay() with context.CreateTimer() and invoke it from the main orchestrator via context.CallSubOrchestratorAsync().

MarkXA
  • 4,294
  • 20
  • 22
  • sure I also thought about refactoring this in the way your described but found CreateTimer supports timeout scenario and doesn't really do polling scenario. I could extend it further to an external wait pattern but that is far too glamorous for what I'm doing. ;o) – puri May 16 '19 at 13:11
  • Just remember to use it in an **activity**, not in the **orchestration** directly. The latter wouldn't work, as things currently stand. – Yam Marcovic Nov 26 '21 at 08:51