Avi*_*til 7 c# azure azure-functions timer-trigger
我有Azure功能与计时器触发器.
public static void Run([TimerTrigger("0 */15 * * * *"), Disable("True")]TimerInfo myTimer, TraceWriter log)
Run Code Online (Sandbox Code Playgroud)
这里Disable("true")不起作用.它产生的function.json作为
"disabled": "True",其是不正确的.它应该是"disabled": True,
Disable只接受字符串值.有没有办法改变这个?或任何其他方式来禁用功能?
禁用属性默认值为true.
用Disable()而不是Disable("true").
所以代码看起来像
public static void Run([TimerTrigger("0 */15 * * * *"), Disable()]TimerInfo myTimer, TraceWriter log) .
如果要启用该功能使用Disable("False").
功能 2.x 可以通过local.settings.json以下方式单独禁用
{
"IsEncrypted": false,
"Values": {
"AzureWebJobs.MyFunctionNameOne.Disabled": "true",
"AzureWebJobs.MyFunctionNameTwo.Disabled": "true",
...
}
}
Run Code Online (Sandbox Code Playgroud)
参考:https : //docs.microsoft.com/en-us/azure/azure-functions/disable-function#functions-2x---all-languages
我想添加这个答案,因为我也一直在寻找它,并且我相信我找到了一个很好的方法来禁用用于调试/开发目的的功能(并避免这些本地更改进入部署管道/源代码控制)。
我将#if DEBUG语句与Disable(string SettingsName)属性结合起来:
以下代码显示了不同的工作方式:
RunOnStartup = true使用TimerTrigger. 这个(我只使用 DEBUG 编译器指令启用)将允许我立即触发计时器功能,而无需等待下一个 CRON 周期发生。(另一种方法是向您的本地函数端点发帖,如本 stackoverflow post 中所述)。因此,再次假设您在 RELEASE 配置中运行生产工作负载时,这只会影响您的本地开发环境,而不是您的开发团队或版本。第一个片段(属性)
#if DEBUG
[Disable("disable-transactioncrawler")]
#endif
[FunctionName("TransactionCrawler")]
public async Task Run([TimerTrigger("50 */10 * * * *"
#if DEBUG
, RunOnStartup = true
#endif
)]TimerInfo myTimer, ILogger log)
{
// Logic comes here
}
Run Code Online (Sandbox Code Playgroud)
第二个片段(local.appsettings.json)
{
"Values":
{
"disable-transactioncrawler": false
}
}
Run Code Online (Sandbox Code Playgroud)
以下“解决方案”通常会影响您的生产代码,这可能会导致问题:
Disable()不允许您事后配置/更改它小智 5
您是否尝试过修改解决方案中的host.json?它具有以下属性供您指定在运行时加载哪些函数。
// Array of functions to load. Only functions in this list will be enabled.
// If not specified, all functions are enabled.
"functions": ["QueueProcessor", "GitHubWebHook"]
Run Code Online (Sandbox Code Playgroud)
请注意,如果您的解决方案中有多个Function App项目,您还需要更改其相应的host.json(即每个项目都有自己的host.json)
文档:https ://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json
| 归档时间: |
|
| 查看次数: |
3109 次 |
| 最近记录: |