在外部托管的网站上运行基于队列的后台进程

发布于 2024-10-09 17:22:27 字数 499 浏览 0 评论 0原文

我有一个 ASP.NET MVC Web 应用程序,由外部提供商托管在 IIS 7 上。

我希望每 15 分钟左右运行一个进程,它检查需要发送的积压电子邮件,并实际发送它们。

似乎执行此操作的正常方法是使用 Microsoft Message Queue,但由于这是我无法直接控制的托管环境,因此我将无法安装或配置 MSMQ。

到目前为止,我决定通过将行附加到我的 SQL Server 数据库(同一托管)中的表中来实现此目的。

那么我应该如何实现检查积压和发送电子邮件的部分呢?

它应该是我的主 Web 应用程序中的某种单独线程,每 15 分钟重新启动一次吗?

我考虑的另一个选择是打开一个 HTTP-POST 接口,当使用适当的管理员密码调用该接口时,会运行电子邮件发送器的迭代。

然后,我可以在本地 PC 上创建一个小型控制台应用程序,该应用程序每 15 分钟调用一次接口。

第一个选项更简单,但第二个选项可能更强大。

有什么想法吗?

I have an ASP.NET MVC web application which is hosted by an external provider, on IIS 7.

I wish to run a process every 15 minutes or so, which checks a backlog of emails that need to be sent, and actually sends them.

It seems that the normal way to do this is with Microsoft Message Queue, but since this is a hosted environment which I can't directly control, I won't be able to install or configure MSMQ.

So far I've decided to do it by appending rows to a table in my SQL Server database (same hosting).

So how should I implement the bit where I check the backlog and send the emails?

Should it be some kind of separate thread in my main web application, which restarts itself every 15 minutes?

Another option I considered was just opening an HTTP-POST interface which, when called with an appropriate admin password, runs an iteration of the email sender.

I could then create a small console app on my local PC which calls the interface every 15 minutes.

The first option is simpler, but the second might be more robust.

Any ideas?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬心 2024-10-16 17:22:28

Jeff Atwood 发表了一篇文章,介绍了他最初如何在 Stack Overflow 上使用过期缓存来定期重置进程来实现徽章系统。

https://blog.stackoverflow.com/2008/07/easy-background-tasks -in-aspnet/

我过去每天都做过类似的事情发送电子邮件。这项服务不是必需的,如果电子邮件错过一两天也没关系,因为无论如何它们最终都会消失,但系统运行得很好。它全部是 asp.net,因此在我使用的托管环境中运行良好,无需访问服务器上的服务或从桌面创建本地触发器。

Jeff Atwood did a post on how he originally achieved the badge system on Stack Overflow using an expiring cache to reset the process periodically.

https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/

I have done something similar to this in the past sending emails out every day. The service was non essential, and it didn't matter if the emails missed a day or two, as they would go out eventually anyway, but the system worked quite well. It's all asp.net so works fine in the hosting environments I use, without access to service on the server or creating a local trigger from your desktop.

情未る 2024-10-16 17:22:27

我建议您查看 Quartz.NET。您还应该注意的一件重要事情是,如果不使用 ASP.NET 应用程序,Web 服务器可能会从内存中卸载它,这意味着所有已生成的线程都会终止。这就是为什么此类任务不应在 ASP.NET 应用程序中执行,而应在 Windows 服务中卸载的原因之一。

I would recommend you taking a look at Quartz.NET. Also an important thing you should be aware is that the web server could unload the ASP.NET application from memory if it is not used meaning that all threads that have been spawned would simply die. That's one of the reasons why such tasks shouldn't be performed in ASP.NET applications but rather offloaded in Windows Services.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文