Aybuke
Aybuke

Reputation: 211

Azure Function Cron expression for excluding a defined time

I want to do very basic cron job on Azure Function. I'm writing functions on Visual Studio and the functions will be dockerized job. There are two different azure function on my solution.

  1. Runs for every month. (Refreshes whole table).
  2. Runs for every five minutes. (Refhreshes just feature records. Not historical records.)

My expectation is that the functions shouldn't block eachother. So, they shouldn't work at the same time. My cron expressions for the functions are;

I don't want to run function2 on every month like 01/01/2021 00:00:00. How can I exclude the time from function2?

Upvotes: 0

Views: 416

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 29940

There is no direct way to do that.

As a workaround, you can add if else code block in Function2. For example, in the if block, you can determine if it's the time like 01/01/2021 00:00:00. if yes, then do nothing. If not, then go to the else block to execute your logic.

Like below:

public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
{
    var the_time = DateTime.Now;

    //if the date is the first day of a month, and time is 00:00:00
    if(the_time.Day==1 && the_time.ToLongTimeString().Contains("00:00:00"))
    {
      //do nothing, don't write any code here.
    }
    else
   {
      //write your code logic here
   }

}

Upvotes: 1

Related Questions