Azure WebJob 在处理时突然关闭

Azure WebJob sudden shutdown while processing

我有一个连续的 Azure WebJob,设置为 'Always On'。 此 WebJob 应该处理添加到存储队列的新消息。

我想知道如果 WebJob 在处理队列触发器时由于某种原因停止工作怎么办。这样我会丢失队列中的消息,它不会进入毒队列。

我该如何解决这个问题?

I'm wondering what if for some reason the WebJob has stopped working while it was processing a queue trigger.

首先,如果 WebJob 会在处理消息时退出,您不必担心数据损坏。当WebJob 访问消息进行处理时,它会将消息隐藏在队列中一定时间。如果您的 WebJob 在处理消息时关闭,该消息将在一段时间后再次可用,并且将重新抓取并 运行 根据更新的 code.About 详细信息,您可以参考这个.

至于您关于通知作业正在关闭的要求。您可以使用 Graceful Shutdown and listen to CancellationToken you can pass to you triggered function and judge the property IsCancellationRequired value , then you could handle the WebJob would shut down. Here 是关于 CancellationToken.

的示例代码