Reputation: 13955
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.
Upvotes: 6
Views: 3262
Reputation: 49095
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)])
Upvotes: 13