3

I'm using Visual Studio to write a class library which contains several Azure functions. There is a combination of timer and queue triggered functions. If I'm working on one of the functions and want to debug only it I have to comment out the other functions to keep them also from executing. Is there a way to easily indicate that I only want a subset of the entire set of functions to execute when debugging locally?

Scott Chamberlin
  • 724
  • 2
  • 8
  • 23

3 Answers3

4

You can configure which functions to load in your host.json (full spec here.) Specifically, you'll want to define a top-level functions property:

{
    "functions": [ "QueueProcessor", "GitHubWebHook" ]
}

(Note this is only meant for local use; you'll want to use the function.json disabled property for published functions.)

Katy Shimizu
  • 1,051
  • 5
  • 9
2

You could make use of the Disable() attribute, however, that's not much better than commenting out code:

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

You could combine the Disable() attribute with #if directive, but it clutters up your code. The Disable() attribute will only be applied if DEBUG is defined.

The following function will run if in release mode, and is disabled if in debug mode.

    [FunctionName("TimerFunction")]
    public static void Run([
        #if DEBUG 
            TimerTrigger("*/5 * * * * *"), Disable()
        #else
            TimerTrigger("*/5 * * * * *")
        #endif
        ]TimerInfo myTimer, TraceWriter log)
    {
        log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
    }
Andy T
  • 10,223
  • 5
  • 53
  • 95
0

You can decorate your function with a DisableAttribute controlled by a settingName from the local.settings.json file.

The following is an example:

[QueueTrigger("%queueName%", Connection = "queues"), Disable("MyFuncABC")]ProcessMessage msg,
Roman Kiss
  • 7,925
  • 1
  • 8
  • 21