Azure Webjobs - 使用 INameResolver 和 TimerTrigger 函数

Tho*_*mas 5 azure-webjobs azure-webjobssdk

我尝试使用 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);
    }
}
Run Code Online (Sandbox Code Playgroud)

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

<add key="Processor.TimerTrigger" value="00:01:00" />
<add key="Processor.Disable" value="false" />
Run Code Online (Sandbox Code Playgroud)

启动我的 webjob 时,我已将作业配置为使用 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();
}
Run Code Online (Sandbox Code Playgroud)

执行该行时host.RunAndBlock(),我遇到了以下异常:

Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException:错误索引方法“ProcessMessages”---> System.FormatException:字符串未被识别为有效的时间跨度。

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

有没有办法用 TimerTrigger 配置 NameResolver ?

谢谢。

mat*_*ewc 4

TimerTrigger 目前不支持INameResolver. 请在此处的公共存储库中打开一个问题,我们将添加该支持。其他扩展绑定支持INameResolver. 如果这对您很重要,我们可以提供预发布版本供您在实际的下一个版本之前使用/验证。