Azure WebJob, how to be notified if it stops?

不想你离开。 提交于 2019-12-07 20:16:38

问题


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?

Thanks!


回答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)
}

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.



来源:https://stackoverflow.com/questions/33159594/azure-webjob-how-to-be-notified-if-it-stops

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!