设计用于ASP.NET的异步任务库 [英] Designing an asynchronous task library for ASP.NET

查看:100
本文介绍了设计用于ASP.NET的异步任务库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET运行时是用于那些可以并行运行的短期工作负载。我需要能够调度周期性事件和后台任务,可能会或可能不会为多长时间运行。

The ASP.NET runtime is meant for short work loads that can be run in parallel. I need to be able to schedule periodic events and background tasks that may or may not run for much longer periods.

鉴于以上情况,我有以下问题需要解决:

Given the above I have the following problems to deal with:


  • 的AppDomain中可以关闭,由于变化(Web.config文件,垃圾桶,APP_ code等。)

  • IIS回收的程序池定期(每天)

  • IIS本身可能重新启动,或者就此而言,服务器可能会崩溃

我不相信里面运行ASP.NET这个code是不正确的事情,原因是其将允许一个简单的编程模型。但这样做需要一个外部的服务会定期发出请求的应用程序,以便应用程序keept运行,而且所有后台任务与绝对最在乎的编程。他们必须能够暂停和恢复thier工作,在一个意想不到的错误事件。

I'm not convinced that running this code inside ASP.NET is not the right thing to do, becuase it would allow for a simpler programming model. But doing so would require that an external service periodically makes requests to the app so that the application is keept running and that all background tasks are programmed with utter most care. They will have to be able to pause and resume thier work, in the event of an unexpected error.

我目前的思路是这样的:

My current line of thinking goes something like this:

如果所有作业都在数据库中注册,应该是可以使用数据库作为簿记机制。在出现错误的情况下,该数据库将包含所有必要的状态以给定的下一个机会,以恢复该操作。

If all jobs are registered in the database, it should be possible to use the database as a bookkeeping mechanism. In the case of an error, the database would contain all state necessary to resume the operation at the next opportunity given.

我真的appriecate一些反馈/建议,在这个问题上。我一直在考虑运行一个Windows服务和使用一些RPC解决方案,以及,但它不具有相同的吸引我。而且我不是有很多的部署问题和sycnhronizing任务和code跨多个应用程序。由于我的业务需求,这是不到optimial。

I'd really appriecate some feedback/advice, on this matter. I've been considering running a windows service and using some RPC solution as well, but it doesn't have the same appeal to me. And I'd instead have a lot of deployment issues and sycnhronizing tasks and code cross several applications. Due to my business needs this is less than optimial.

推荐答案

这是在黑暗中,因为我不知道你用什么数据库了一枪,但我建议你考虑的对话框定时器并的激活。假设的大多数工作的必须做一些数据操作,并很可能的所有的必须做的只有的数据处理,利用活化和计时器举一个非常可靠的作业调度解决方案,完全嵌入数据库(无需外部进程/服务,而不是依赖数据库界限像MSDB外),并且是确保计划的作业可以生存重启,故障切换事件,甚至灾难的解决方案恢复恢复。简单地说,一旦作业计划如果数据库恢复一周后在不同的机器上它甚至会运行。

This is a shot in the dark since I don't know what database you use, but I'd recommend you to consider dialog timers and activation. Assuming that most of the jobs have to do some data manipulation, and is likely that all have to do only data manipulation, leveraging activation and timers give an extremely reliable job scheduling solution, entirely embedded in the database (no need for an external process/service, not dependencies outside the database bounds like msdb), and is a solution that ensures scheduled jobs can survive restarts, failover events and even disaster recovery restores. Simply put, once a job is scheduled it will run even if the database is restored one week later on a different machine.

看一看异步过程执行一个相关的例子

如果这是过于激进,至少看看使用表作为队列因为在数据库中存储预定的项目往往属于未决队列情况下。

And if this is too radical, at least have a look at Using Tables as Queues since storing the scheduled items in the database often falls under the 'pending queue' case.

这篇关于设计用于ASP.NET的异步任务库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆