2016-02-01 75 views
1

我试着用TimerTrigger配置一个具有简单函数的作业。Azure Webjobs - 使用带定时器触发器的INameResolver函数

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" /> 

开始时我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(); 
} 

当执行行host.RunAndBlock(),我有这个例外:

Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException:错误索引方法'ProcessMessages'---> System.FormatException:String未被识别为有效的TimeSpan。

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

有什么办法用TimerTrigger配置NameResolver?

谢谢。

回答

2

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

+0

感谢马修,我已经创建了一个新的问题https://github.com/天青/蔚webjobs-SDK-扩展/问题/ 33。如果你能发布预发布,我将很乐意测试它。 – Thomas

0

确认INameResolver现在支持定时器触发使用原来的问题的技术,看起来像这样一个解析器:

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