问题描述
我创建了我的第一个可连续运行的天蓝色webjob;
I have created my first azure webjob that runs continously;
我不太确定这是一个代码问题,但是为了完整起见,这里是我的代码:
I'm not so sure this is a code issue, but for the sake of completeness here is my code:
static void Main()
{
var host = new JobHost();
host.CallAsync(typeof(Functions).GetMethod("ProcessMethod"));
host.RunAndBlock();
}
对于函数:
[NoAutomaticTrigger]
public static async Task ProcessMethod(TextWriter log)
{
log.WriteLine(DateTime.UtcNow.ToShortTimeString() + ": Started");
while (true)
{
Task.Run(() => RunAllAsync(log));
await Task.Delay(TimeSpan.FromSeconds(60));
}
log.WriteLine(DateTime.UtcNow.ToShortTimeString() + "Shutting down..");
}
请注意,异步任务会触发自己的任务.这是为了确保它们以相同的间隔非常准确地启动.工作本身就是下载一个url,解析并在db中输入一些数据,但这不应该与我遇到的多实例问题有关.
Note that the async task fires off a task of its own. This was to ensure they were started quite accurately with the same interval. The job itself is to download an url, parse and input some data in a db, but that shouldnt be relevant for the multiple instance issue I am experiencing.
我的问题是,一旦运行了大约5分钟,就会调用第二个ProcessMethod,这使我有两个会话同时执行相同的操作.第二种方法说它是从仪表板开始",即使我100%确信我没有单击任何东西来自己启动它.
My problem is that once this has been running for roughly 5 minutes a second ProcessMethod is called which makes me have two sessions simoultaniously doing the same thing. The second method says it is "started from Dashboard" even though I am 100% confident I did not click anything to start it off myself.
有人经历过类似的事情吗?
Anyone experienced anything like it?
推荐答案
从Azure门户中WebApp的缩放"选项卡将实例计数更改为1.默认情况下,它设置为2个实例,这导致它运行两次.
Change the instance count to 1 from Scale tab of WebApp in Azure portal. By default it is set to 2 instances which is causing it to run two times.
这篇关于为什么我的连续天蓝色webjob运行两次该功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!