0

I want to send an email for every one hour and there is threshold value property in local.settings.json if threshold is reached I need to send an email for every 30 mins.

Here is my code:

       [FunctionName("StatusReport1hourFunction")]
    public async Task RunAsync([TimerTrigger("0 0 * * * *", RunOnStartup = true)] TimerInfo myTimer, ILogger log)
    {
        log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

       await SendStatustoEmailAsync(log);
    }
    
    public async Task SendStatustoEmailAsync(ILogger log)
    {
    // get the data from db 
        
    
    // prepare the data to send the email
    
    
    // send the email using send grid
    
    // checking threshold
    if(a > threshold)
        {
         // get the data by above process and send email for every 30 mins
        }
        else{
            //send the email for one hour
        }
    }

how to do this approach. here are my findings

  1. I have done lot of research for this. Configuring the cron expression in local.settings.json, however those properties are read only.

  2. I thought of 2 time trigger function in single file. However how to do with this approach I was unaware any suggestions disabling 30 mins time trigger when threshold reached when threshold is normal should enable one hour time trigger function should run

halfer
  • 19,824
  • 17
  • 99
  • 186
prasanthi
  • 562
  • 1
  • 9
  • 25
  • Note that we prefer a technical style of writing here. We gently discourage greetings, hope-you-can-helps, thanks, advance thanks, notes of appreciation, regards, kind regards, signatures, please-can-you-helps, chatty material and abbreviated txtspk, pleading, how long you've been stuck, voting advice, meta commentary, etc. Just explain your problem, and show what you've tried, what you expected, and what actually happened. – halfer Aug 21 '23 at 10:08
  • A reminder that you've [received this advice previously](https://stackoverflow.com/questions/74193917/usage-of-concurrentbagt-vs-listt#comment131384606_74193917). – halfer Aug 21 '23 at 10:09

1 Answers1

2

I'd suggest you switch to Durable Functions, Timers, for your scenario. You can set the wait time between activity executions a lot more flexible then.

https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-timers?tabs=csharp

silent
  • 14,494
  • 4
  • 46
  • 86