Disable Property of Azure Functions not working in Visual Studio 2017

只愿长相守 提交于 2019-12-07 01:00:41

问题


I have Azure function with timer trigger.

public static void Run([TimerTrigger("0 */15 * * * *"), Disable("True")]TimerInfo myTimer, TraceWriter log)

Here the Disable("true") is not working. it generates the function.json as "disabled": "True", which is not correct. It should be "disabled": True, Disable only accepts string value. Is there any way to change this? or any other way to disable function?


回答1:


Disable properties default values is true.

Use Disable() instead of Disable("true").

So the code will look like

public static void Run([TimerTrigger("0 */15 * * * *"), Disable()]TimerInfo myTimer, TraceWriter log) .

If you want to enable the function use Disable("False").




回答2:


Have you tried modifying the host.json inside your solution? It has the following properties for you to specify which functions to load on runtime.

// Array of functions to load. Only functions in this list will be enabled.
// If not specified, all functions are enabled.
"functions": ["QueueProcessor", "GitHubWebHook"]

Note that if you have multiple Function App projects in your solution, you will also need to make to change to their corresponding host.json (i.e. each project has their own host.json)

Documentation: https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json




回答3:


Functions 2.x can be disabled individually via local.settings.json in the following manner

{
    "IsEncrypted": false,
    "Values": {
    "AzureWebJobs.MyFunctionNameOne.Disabled": "true",
    "AzureWebJobs.MyFunctionNameTwo.Disabled": "true",
    ...
    }
}

Ref: https://docs.microsoft.com/en-us/azure/azure-functions/disable-function#functions-2x---all-languages




回答4:


The string typed value - "disabled": "true" also could disable the function. Please see the test result as following.

Here is my function definition.

public static void Run([TimerTrigger("0 */5 * * * *"),Disable("true")]TimerInfo myTimer, TraceWriter log)

Here is the published function on Azure portal.




回答5:


I tried disabling using local.settings.json, and when debugging locally the emulator window actually says that the named function is disabled, but calls it anyway! This is the same in VS2017 and 2019.

The workaround I'm currently using is to test for this app setting as the first line in my function and return immediately:

    if(ConfigurationManager.AppSettings["AzureWebJobs.TimerTriggeredFunction.Disabled"] == "true") return;


来源:https://stackoverflow.com/questions/45749508/disable-property-of-azure-functions-not-working-in-visual-studio-2017

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!