5
votes

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.

2

2 Answers

4
votes

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.

3
votes

Confirmation that INameResolver is now supported in Timer Triggers using the technique in the original question and a resolver that looks like this:

public class ConfigNameResolver : INameResolver
{
    public string Resolve(string name)
    {
        return ConfigurationManager.AppSettings.Get(name);
    }
}