Hangfire 如何处理应用域重启?

How does Hangfire handle app domain restarts?

在我的 ASP.NET MVC 应用程序中,我将执行 运行 后台任务,有时会持续约 10 分钟。我已经阅读了有关该主题的内容,发现应用程序域有时会重新启动,从而删除了我的讨论帖。

因此我查找了一些解决方案。我找到的主要解决方案是 Hangfire。我知道它会在作业失败等时重新启动作业,但是它们 "bypass" 应用程序域会以某种方式重新启动还是只是在这种情况下重新启动作业?

The primary solution I found is Hangfire. I understand that it restarts jobs when they fail etc., however do they "bypass" the app domain restart somehow or does it just restart the jobs in that case?

不,他们不会绕过应用程序域重启 - 没有什么可以绕过它。引自 documentation:

Hangfire keeps background jobs and other information that relates to the processing inside a persistent storage. Persistence helps background jobs to survive on application restarts, server reboots, etc. This is the main distinction between performing background jobs using CLR’s Thread Pool and Hangfire. Different storage backends are supported.

所以当你入队一个新任务时,首先要做的是将它存储在服务器上的一些持久存储中,而不是将它保存在内存中。这样,如果应用程序域死了,以后可以从这个持久存储中读取和恢复任务。