Azure 定时器触发的 webjob 随机挂起
Azure timertriggered webjob hangs randomly
我想安排一个 timertriggered 方法来调用其他方法,但不知何故 CronJob 方法不会 运行 如果我用它来调用我自己的方法之一,我只是得到这个控制台输出:
“
发现了以下函数:
...ProcessQueueMessage
...Functions.CronJob
作业主机已启动
“
几分钟内没有任何其他事情发生,然后它可能会突然开始工作。但是,如果我仅将 CronJob() 方法用于 运行ning 它自己的 Console.WriteLine("Timer job fired") 语句一切正常。
几个小时以来,我一直在努力寻找这个问题的解决方案,但似乎没有人遇到同样的问题。关于我做错了什么的任何想法?
public static void CronJob([TimerTrigger("*/3 * * * * *", RunOnStartup = true)] TimerInfo timerInfo)
{
Console.WriteLine("Timer job fired! ");
DoTask();
}
private static void DoTask()
{
Console.WriteLine("Doing task...");
}
主要方法:
static void Main()
{
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost(config);
config.UseTimers();
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
Any ideas on what I'm doing wrong?
根据您的描述,是否直接调用代码与无关。根本原因是 blob 租约(单例锁)的默认时间为 30 秒。
正如 Rob Reagan 提到的那样,您可以设置 JobHostConfiguration.Tracing.ConsoleLeve
到冗长。当 webjob 挂起时,您可以获得信息 "Unable to aquire Singleton lock".
更多详细信息,您可以参考此issue。
When the listener starts for a particular TimerTrigger function, a blob lease (the Singleton Lock) is taken for a default time of 30 seconds. This is the lock that ensures that only a single instance of your scheduled function is running at any time. If you kill your console app, that lease will still be held until it expires naturally
我想安排一个 timertriggered 方法来调用其他方法,但不知何故 CronJob 方法不会 运行 如果我用它来调用我自己的方法之一,我只是得到这个控制台输出: “ 发现了以下函数: ...ProcessQueueMessage ...Functions.CronJob 作业主机已启动 “
几分钟内没有任何其他事情发生,然后它可能会突然开始工作。但是,如果我仅将 CronJob() 方法用于 运行ning 它自己的 Console.WriteLine("Timer job fired") 语句一切正常。
几个小时以来,我一直在努力寻找这个问题的解决方案,但似乎没有人遇到同样的问题。关于我做错了什么的任何想法?
public static void CronJob([TimerTrigger("*/3 * * * * *", RunOnStartup = true)] TimerInfo timerInfo)
{
Console.WriteLine("Timer job fired! ");
DoTask();
}
private static void DoTask()
{
Console.WriteLine("Doing task...");
}
主要方法:
static void Main()
{
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
var host = new JobHost(config);
config.UseTimers();
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
Any ideas on what I'm doing wrong?
根据您的描述,是否直接调用代码与无关。根本原因是 blob 租约(单例锁)的默认时间为 30 秒。
正如 Rob Reagan 提到的那样,您可以设置 JobHostConfiguration.Tracing.ConsoleLeve 到冗长。当 webjob 挂起时,您可以获得信息 "Unable to aquire Singleton lock".
更多详细信息,您可以参考此issue。
When the listener starts for a particular TimerTrigger function, a blob lease (the Singleton Lock) is taken for a default time of 30 seconds. This is the lock that ensures that only a single instance of your scheduled function is running at any time. If you kill your console app, that lease will still be held until it expires naturally