简体   繁体   English

在长时间运行过程中使用NHibernate更新状态表

[英]Using NHibernate to update status table during long running process

I have inherited a project that implements multiple long running processes. 我继承了一个实现多个长时间运行的流程的项目。 Each of those processes update a status table that is then reflected on the UI via ajax polling. 这些进程中的每一个都会更新状态表,然后通过ajax轮询将其反映在UI上。 These process are running in a background application that uses Rhino Service Bus (with MSMQ), and the process is triggered by sending an "execute long process" message. 这些过程在使用Rhino Service Bus(带有MSMQ)的后台应用程序中运行,并且通过发送“执行长过程”消息来触发该过程。

The process itself is doing all kinds of data manipulation, validation, updates, inserts deletes etc. on numerous tables. 该过程本身正在对许多表进行各种数据处理,验证,更新,插入删除等操作。

It seems like it is really abusing the NHibernate session with multiple sessions and nested TransactionScopes all over the place. 似乎真的在滥用NHibernate会话,因为它遍地都是多个会话和嵌套的TransactionScopes。

My question to the NHibernate / RSB experts out there, is how would you update a status table during the execution of a long running process? 我对NHibernate / RSB专家的问题是,在长时间运行的过程中如何更新状态表?

I have thought about: 我考虑过:

  • sending an "update status message" during the execution of the process (will need to workout the NHibernate / RSB session management issues). 在执行过程中发送“更新状态消息”(将需要解决NHibernate / RSB会话管理问题)。
  • using a saga with database persister and have the ajax polling functions query it instead of a status table 将saga与数据库持久性一起使用,并让ajax轮询功能查询它而不是状态表

The problem with status updates within a RSB process is that typically, the message processing happens inside a transaction scope itself. RSB流程中状态更新的问题在于,通常,消息处理发生在事务作用域自身内部。 This means that any changes to the database, or messages you send, will only (typically) be visible to other applications once the transaction is committed (which happens when processing the message is complete). 这意味着一旦提交事务(对消息的处理完成时会发生),对数据库或您发送的消息的任何更改将(通常)仅对其他应用程序可见。

There are 3 approaches I typically take: 我通常采用3种方法:

  1. wrap the updates in a TransactionScope that suppresses the ambient transaction (I suspect that this is what is currently happening) 将更新包装在抑制周围事务的TransactionScope中(我怀疑这是当前正在发生的事情)
  2. break the process down into smaller messages (this could reduce contention on the database, but at the cost of having more messages flying around) 将过程分解为较小的消息(这可以减少数据库上的争用,但是会浪费更多的消息)
  3. notify external clients by means of some other process (eg. have some kind of remoting service / WCF / rest service that other processes can query, or send out notifications via some kind of transaction ignorant process) 通过某些其他进程来通知外部客户端(例如,具有其他进程可以查询的某种远程服务/ WCF / REST服务,或通过某种对事务无知的进程发出通知)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM