Azure 触发的 Webjob

编程入门 行业动态 更新时间:2024-10-20 01:31:33
本文介绍了Azure 触发的 Webjob - 检测 webjob 何时停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个使用 定时器触发器.

I am developing a triggered webjob that use TimerTrigger.

在webjob停止之前,我需要处理一些对象,但我不知道如何触发webjob stop".

Before the webjob stops, I need to dispose some objects but I don't know how to trigger the "webjob stop".

拥有 NoAutomaticTrigger 功能,我知道我可以使用 WebJobsShutdownWatcher 类在 webjob 停止但触发作业时处理我需要一些帮助...

Having a NoAutomaticTrigger function, I know that I can use the WebJobsShutdownWatcher class to handle when the webjob is stopping but with a triggered job I need some help...

我看了使用 Azure WebJobs SDK 1.1.0-alpha1 的可扩展触发器和绑定器.

创建一个使用 WebJobsShutdownWatcher 类在 webjob 停止之前触发动作的自定义触发器 (StopTrigger) 是个好主意吗?

Is it a good idea to create a custom trigger (StopTrigger) that used the WebJobsShutdownWatcher class to fire action before the webjob stops ?

推荐答案

好的 答案就在问题中:

Ok The answer was in the question :

是的,我可以使用 WebJobsShutdownWatcher 类,因为它有一个 Register 函数,在取消令牌被取消时调用,换句话说,当 webjob 停止时.

Yes I can use the WebJobsShutdownWatcher class because it has a Register function that is called when the cancellation token is canceled, in other words when the webjob is stopping.

static void Main() { var cancellationToken = new WebJobsShutdownWatcher().Token; cancellationToken.Register(() => { Console.Out.WriteLine("Do whatever you want before the webjob is stopped..."); }); var host = new JobHost(); // The following code ensures that the WebJob will be running continuously host.RunAndBlock(); }

编辑(基于马修评论):

如果您使用触发函数,您可以将 CancellationToken 参数添加到您的函数签名中.当主机自动关闭时,运行时将取消该令牌,从而允许您的函数接收通知.

If you use Triggered functions, you can add a CancellationToken parameter to your function signatures. The runtime will cancel that token when the host is shutting down automatically, allowing your function to receive the notification.

public static void QueueFunction( [QueueTrigger("QueueName")] string message, TextWriter log, CancellationToken cancellationToken) { ... if(cancellationToken.IsCancellationRequested) return; ... }

更多推荐

Azure 触发的 Webjob

本文发布于:2023-11-14 04:25:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586211.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Azure   Webjob

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!