【问题标题】:Azure Webjobs - Use INameResolver with TimerTrigger FunctionAzure Webjobs - 将 INameResolver 与 TimerTrigger 函数一起使用
【发布时间】:2016-05-09 09:13:10
【问题描述】:

我尝试用 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:错误索引方法“ProcessMessages”---> System.FormatException:字符串未被识别为有效的 TimeSpan。

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

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

谢谢。

【问题讨论】:

    标签: azure-webjobs azure-webjobssdk


    【解决方案1】:

    TimerTrigger 当前不支持INameResolver。请在公共回购here 中打开一个问题,我们将添加该支持。其他扩展绑定支持INameResolver。如果它对您很重要,我们可以发送pre-release build 供您在实际下一个版本发布之前使用/验证。

    【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-12-05
      • 2016-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多