在Azure Function中以编程方式设置RunOnStartup? [英] Programmatically set RunOnStartup in Azure Function?

查看:127
本文介绍了在Azure Function中以编程方式设置RunOnStartup?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Azure函数.在本地主机上测试时,我希望它立即执行.但是在Prod中,它可以每5分钟运行一次.我不想依靠人类记住这一改变.

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)])

我一直在尝试各种方法来使 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)])

但是不允许内联#DEBUG.

But inline #DEBUG is not allowed.

推荐答案

为了获得更好的可读性,您可以定义一个常量 bool 来表示您是否正在运行DEBUG构建:

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)])

这篇关于在Azure Function中以编程方式设置RunOnStartup?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆