Azure Webjobs - 将 INameResolver 与 TimerTrigger 函数结合使用

Azure Webjobs - Use INameResolver with TimerTrigger Function

我尝试用一​​个带有 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);
    }
}

我的设置在我的 app.config 文件中定义:

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

启动我的网络作业时,我已将作业配置为使用 INameResolver 和 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();
}

当执行行 host.RunAndBlock() 时,我遇到了这个异常:

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

我在实现 INameResolver 接口但从未命中的 class 中放置了一个断点。

有什么方法可以用 TimerTrigger 配置 NameResolver 吗?

谢谢。

TimerTrigger 目前不支持 INameResolver。请在 public 回购 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 中为您 use/verify 在实际的下一个版本之前打开一个问题。

使用原始问题中的技术和如下所示的解析器确认定时器触发器现在支持 INameResolver:

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