处理 Windows 服务中嵌入的 Quartz.NET 调度程序的异常

发布于 2024-12-14 06:52:31 字数 844 浏览 0 评论 0原文

我使用 Quartz.NET 作为 Windows 服务的嵌入式调度程序。

Quartz 配置为使用 AdoJobStore,每次 SQL 服务器由于某种原因不可用时,Quartz 都会抛出 Quartz.JobPersistenceException 异常,从而终止我的 Windows 服务。

显然,Quartz IScheduler 是从我的服务的 OnStart 内的 try...catch 块中实例化并启动的,但是一旦 >IScheudler 已启动并运行 Quartz 抛出的任何异常都不再被该 catch 块捕获...

有关如何防止 Quartz 异常在这种情况下杀死我的 Windows 服务的任何想法都是欢迎...

我知道我可以在服务的“恢复”选项卡中将服务设置为崩溃后重新启动,但它是一个补丁,而不是真正的解决方案...

编辑:

这些异常是从 JobStoreSupport 的 ConnectionAndTransactionHolder 方法中引发的当该方法无法获取并打开数据库连接或调用 BeginTransaction 失败时,Quartz.NET 库的 类会执行此操作。由于 Quartz.NET 是开源的,并且我可以访问此代码,因此我可以直接注释掉引发这些 JobPersistenceException 异常的代码,但无需详细分析 Quartz.NET 的源代码,我不知道是什么如果 Quartz 会继续尝试扫描触发器,直到数据库连接再次可用或不可用......而且我不确定许可协议是否允许对源代码进行任何修改......

I'm using Quartz.NET as an embedded scheduler for my windows service.

Quartz is configured to use AdoJobStore and every time the SQL server is not available for whatever reason, Quartz throws Quartz.JobPersistenceException exception which kills my windows service.

Obviously, Quartz IScheduler is instantiated and started from within a try...catch block from within the OnStart of my service but once the IScheudler is up and running any exceptions thrown by Quartz are no longer caught by that catch block...

Any ideas on how to prevent Quartz exceptions from killing my windows service in this scenario are welcome...

I am aware that I can set the service to restart after crashing in the Recovery tab of the service but it is a patch, not really a solution...

EDIT:

These exceptions are thrown from within ConnectionAndTransactionHolder method of the JobStoreSupport class of the Quartz.NET library when the method fails to get and open a DB connection or a call to BeginTransaction fails. Since Quartz.NET is open source and I have access to this code I could just comment out the code that throws these JobPersistenceException exceptions but without analyzing in detail the source code of Quartz.NET I have no idea what effect that would have and if Quartz would continue to try scanning for triggers until the DB connection is again available or not... also I'm not sure if the license agreement would allow for any modification of the source code...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文