Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Webjobs - Use INameResolver with TimerTrigger Function

I've tried to configure a job with a simple function with a TimerTrigger.

public class Processor
{
    /// <summary>
    /// Initializes a new instance of the <see cref="Processor"/> class.
    /// </summary>
    public Processor()
    {

    }

    /// <summary>
    /// Process the Leads to Marketo.
    /// </summary>
    [Disable("Processor.Disable")]
    public async Task ProcessMessages([TimerTrigger("%Processor.TimerTrigger%")] TimerInfo timerInfo, TextWriter log)
    {


        // TODO : remove
        await Task.FromResult(0);
    }
}

My settings are defined in my app.config file:

<add key="Processor.TimerTrigger" value="00:01:00" />
<add key="Processor.Disable" value="false" />

When Starting my webjob, I've configure the job to use INameResolver and timertrigger:

static void Main()
{
    // Configure the job host
    var config = new JobHostConfiguration
    {
        NameResolver = new ConfigNameResolver() // Resolve name from the config file.
    };

    config.UseTimers();
    var host = new JobHost(config);
    // The following code ensures that the WebJob will be running continuously

    host.RunAndBlock();
}

When executing the line host.RunAndBlock(), I've got this exception :

Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: Error indexing method 'ProcessMessages' ---> System.FormatException: String was not recognized as a valid TimeSpan.

I've put a break point in the class that implements the INameResolver interface but never hit.

Is there any way to configure a NameResolver with TimerTrigger ?

Thanks.

like image 689
Thomas Avatar asked Feb 01 '16 01:02

Thomas


People also ask

Is Azure WebJobs deprecated?

Azure WebJobs are deprecated, but still in use. They are being phased out in favor of Azure Functions. Azure Functions is a more up-to-date and feature rich service which offers a greater degree of flexibility and control.

What is the difference between Azure functions and WebJobs?

Summary. Azure Functions offers more developer productivity than Azure App Service WebJobs does. It also offers more options for programming languages, development environments, Azure service integration, and pricing. For most scenarios, it's the best choice.

Can Azure function have multiple triggers?

An Azure function can have multiple triggers, but the function must be explicitly configured to use multiple triggers. The Azure function can have a single trigger, or it can have multiple triggers.

Which type of expression should you include in the function trigger?

A CRON expression or a TimeSpan value.


1 Answers

TimerTrigger does not currently support INameResolver. Please open an issue in the public repo here and we'll add that support. The other extension bindings support INameResolver. If it's important to you, we can get out a pre-release build for you to use/verify ahead of the actual next release.

like image 153
mathewc Avatar answered Sep 28 '22 14:09

mathewc