Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Durable entity functions to get & set timestamp info using timer trigger

I am trying to store the time stamp information in durable entities and retrieve it every time a trigger fired. Here is how I am doing it. I want the timestamp value set by the current execution to be available for the next trigger. But when the control reaches "string prevTS = await context.CallEntityAsync(entityId, "Get");" to goes back to start of the function again. What am I missing here.

I want execution to be sequential between the timer triggers. '''

 ***public static class GetOpenDataRealtimeFeed
    {
        [FunctionName("GetOpenDataOrchestrator")]
        public static async Task<List<string>> RunOrchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context, Binder binder, ILogger log)
        {
            var outputs = new List<string>();
            var entityId = new EntityId(nameof(GetPrevLastModifiedTimestamp), "entityKey2");
            string prevTS = await context.CallEntityAsync<string>(entityId, "Get");
            
            string currentTS = DateTime.Now.ToString();
            outputs.Add(currentTS);
            outputs.Add(prevTS);
            context.SignalEntity(entityId, "Set", currentTS);
            return null;

        }

        //Durable entity function to get & set the last modified timestamp
        [FunctionName("GetPrevLastModifiedTimestamp")]
        public static void GetPrevLastModifiedTimestamp([EntityTrigger] IDurableEntityContext ctx)
        {
            switch (ctx.OperationName.ToLowerInvariant())
            {
                case "set":
                    ctx.SetState(ctx.GetInput<string>());
                    break;
                case "get":
                    ctx.Return(ctx.GetState<string>());
                    break;
            }
        }


        [FunctionName("getOpenDataRealtimeFeed_Trigger")]
        public static async Task Run(
            [TimerTrigger("%triggerTimer%")] TimerInfo myTimer,
            [DurableClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            // Function input comes from the request content.
            string instanceId = await starter.StartNewAsync("GetOpenDataOrchestrator", null);
            log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
        }
    }
}*** 

'''

like image 443
Kiran Kumar Avatar asked Dec 11 '25 23:12

Kiran Kumar


1 Answers

I assume you are referring to the current line while debugging. If so, this is expected.

Since Durable Functions replays functions after awaiting a durable client call, execution won't ever go through the first round. Only the final replay will be "sequential" step overs.

like image 130
PramodValavala-MSFT Avatar answered Dec 13 '25 19:12

PramodValavala-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!