对多个 Azure Web 作业 (dev/live) 使用相同的存储帐户时发生了什么?
What happened when using same Storage account for multiple Azure WebJobs (dev/live)?
在我的小工作中,我只对 AzureWebJobsDashboard
和 AzureWebJobsStorage
配置使用相同的存储帐户。
但是当我们对本地调试和发布作业同样使用相同的连接字符串时会发生什么?他们是否被孤立对待?或者他们有什么冲突问题?
我查看了大量已发布的工作,发现 azure-webjobs-dashboad/functions/instances
或 azure-webjobs-dashboad/functions/recent/by-job-run/{jobname}
,或 azure-webjobs-hosts/output-logs
目录;他们没有在作业之间指定鉴别器,而其他一些目录具有带作业名称的 GUID。
请注意,我的工作将 运行 连续进行。
Or do they have any conflict issue?
不,不存在冲突问题。根据我的经验,不 推荐本地调试,而发布的作业在 azure 中 运行 具有相同的连接字符串。以 Azure Storage 队列为例,我们无法控制哪个队列应该在本地或在 Azure 中执行。如果我们尝试在本地调试它,请尝试从 Azure 门户 停止 继续 WebJob。
如果我们试图知道 WebJob 是从哪个实例执行的,我们可以使用环境变量 WEBSITE_INSTANCE_ID
在代码中记录实例信息。以下是代码示例:
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
{
string instance = Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID");
string newMsg = $"WEBSITE_INSTANCE_ID:{instance}, timestamp:{DateTime.Now}, Message:{message}";
log.WriteLine(newMsg);
Console.WriteLine(newMsg);
}
更多信息请参考how to use azure queue storage with the WebJob SDK。以下内容是从文档中截取的。
If your web app runs on multiple instances, a continuous WebJob runs on each machine, and each machine will wait for triggers and attempt to run functions. The WebJobs SDK queue trigger automatically prevents a function from processing a queue message multiple times; functions do not have to be written to be idempotent
更新:
关于计时器触发器,我们可以在 GitHub document 的 WebJob 中找到有关计时器触发器的更多说明。因此,如果您想在本地调试,请尝试从 Azure 门户停止 WebJob。
only a single instance of a particular timer function will be running across all instances (you don't want multiple instances to process the same timer event).
在我的小工作中,我只对 AzureWebJobsDashboard
和 AzureWebJobsStorage
配置使用相同的存储帐户。
但是当我们对本地调试和发布作业同样使用相同的连接字符串时会发生什么?他们是否被孤立对待?或者他们有什么冲突问题?
我查看了大量已发布的工作,发现 azure-webjobs-dashboad/functions/instances
或 azure-webjobs-dashboad/functions/recent/by-job-run/{jobname}
,或 azure-webjobs-hosts/output-logs
目录;他们没有在作业之间指定鉴别器,而其他一些目录具有带作业名称的 GUID。
请注意,我的工作将 运行 连续进行。
Or do they have any conflict issue?
不,不存在冲突问题。根据我的经验,不 推荐本地调试,而发布的作业在 azure 中 运行 具有相同的连接字符串。以 Azure Storage 队列为例,我们无法控制哪个队列应该在本地或在 Azure 中执行。如果我们尝试在本地调试它,请尝试从 Azure 门户 停止 继续 WebJob。
如果我们试图知道 WebJob 是从哪个实例执行的,我们可以使用环境变量 WEBSITE_INSTANCE_ID
在代码中记录实例信息。以下是代码示例:
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
{
string instance = Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID");
string newMsg = $"WEBSITE_INSTANCE_ID:{instance}, timestamp:{DateTime.Now}, Message:{message}";
log.WriteLine(newMsg);
Console.WriteLine(newMsg);
}
更多信息请参考how to use azure queue storage with the WebJob SDK。以下内容是从文档中截取的。
If your web app runs on multiple instances, a continuous WebJob runs on each machine, and each machine will wait for triggers and attempt to run functions. The WebJobs SDK queue trigger automatically prevents a function from processing a queue message multiple times; functions do not have to be written to be idempotent
更新:
关于计时器触发器,我们可以在 GitHub document 的 WebJob 中找到有关计时器触发器的更多说明。因此,如果您想在本地调试,请尝试从 Azure 门户停止 WebJob。
only a single instance of a particular timer function will be running across all instances (you don't want multiple instances to process the same timer event).