3

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}'.");
        }
    }
}*** 

'''

  • you can also use `context.IsReplaying` property on the IDurableOrchestrationContext interface. this property will show you if it's the actual execution vs, the replay to reach the next "await" – Sam Vanhoutte Oct 23 '20 at 07:25

1 Answers1

1

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.

PramodValavala
  • 6,026
  • 1
  • 11
  • 30