Is there one?

If not, what is the recommended best practice?

In my MVC app, I want a service to execute periodically (e.g. every minute) and do some cleanup work. The requirements are:

  1. There should only be one instance of the service running for the entire application.
  2. The service should execute every X minutes.
  3. If there is an exception, the service should try to re-process up to X times.
  4. If there was an exception, this should NOT prevent the service from executing in the future.

The best I can think of is creating a new thread in Application_Start().

UPDATE I created and started a new thread in Application_Start, after setting SessionManager.DomainBuilder. In the worker thread, I call Xtensive.Orm.Session.Demand(), but it throws an exception. Is this because the domain is not yet built? Is there a Domain event I can handle after a domain is built?

Any hooks available natively in DO?

I'd appreciate any tips! Thank you!

asked Jan 04 '11 at 17:17

ara's gravatar image

ara
395868791

edited Jan 05 '11 at 01:32


One Answer:

We don't provide any abstraction similar to RuntimeService from v3.9, so currently you should care about this.

I call Xtensive.Orm.Session.Demand(), but it throws an exception. Is this because the domain is not yet built?

That's because there is no current HtppApplication - SessionManager relies on it, if there is no current Session bound to active thread.

There are two ways to resolve the issue:

  1. Provide another (your own) way to get the Domain in this case, and ensure SessionManager.DomainBuilder event gets the same instance, if it is already built.
  2. Implement IModule handling 'OnDomainBuilt' event in your Domain.

Way two seems better, since in this case your background thread will be started only when the first request that needs a Session will come to your application.

P.S. We'll consider adding this feature.

answered Jan 05 '11 at 23:21

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

edited Jan 05 '11 at 23:22

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×5

Asked: Jan 04 '11 at 17:17

Seen: 2,068 times

Last updated: Jan 05 '11 at 23:22

powered by OSQA