Azure WebJob,如何停止通知?
我有一个持续运行的天蓝色webjob.如果它停止或中止,我想得到通知.是否有一个停止或中止而我可以触发电子邮件的事件被调用?
I have an azure webjob that runs continuously. I'd like to be notified if it stops or is aborted. Is there an event that gets called on stop or abort that I can trigger an email?
谢谢!
如果使用的是WebJob SDK,则可以使用新的ErrorTrigger
和SendGrid
扩展名来实现.检查此有关如何进行设置的维基.但是,这里有一个示例代码(从上面的Wiki复制),如果在30分钟的窗口内发生10次错误,并且节气门长达1小时,则使用这两个扩展名发送电子邮件.
If you're using the WebJob SDK, then you can do that using the new ErrorTrigger
and SendGrid
extensions. Check this wiki on how to set that up. But here is a sample code (copied from the wiki above) that uses both extensions to send an email if an error occurred 10 times in 30 minutes window with a throttle up to 1 hour
public static void ErrorMonitor(
[ErrorTrigger("0:30:00", 10, Throttle = "1:00:00") TraceFilter filter,
[SendGrid] SendGridMessage message)
{
message.Subject = "WebJobs Error Alert";
message.Text = filter.GetDetailedMessage(5)
}
如果您不使用WebJob SDK,那么很遗憾,连续Web作业没有任何事件.有仅用于触发的工作.
If you aren't using the WebJob SDK, then unfortunately there aren't any events for continuous webjobs. There is only one for triggered jobs.