6

I'm creating an Azure function. While testing on my localhost, I'd like it to execute immediately. But in Prod, it can run every 5 minutes. I'd like to not have to rely on humans to remember to make this change.

public static void Run([TimerTrigger("0 */5 * * * *", RunOnStartup = true)])

I've been playing around with various ways to make the true here somehow variable, but have not found a solution. I was thinking something like:

public static void Run([TimerTrigger("0 */5 * * * *", RunOnStartup = #DEBUG ? true : false)])

But inline #DEBUG is not allowed.

Casey Crookston
  • 13,016
  • 24
  • 107
  • 193

1 Answers1

11

For better readability, you can define a constant bool that denotes whether you're running a DEBUG build:

#if DEBUG
    const bool IS_DEBUG = true;
#else
    const bool IS_DEBUG = false;
#endif

Then use it in your attribute:

public static void Run([TimerTrigger("0 */5 * * * *", RunOnStartup = IS_DEBUG)])
haim770
  • 48,394
  • 7
  • 105
  • 133