0

I have a high-level architecture question. I am building an MVC application that needs to do the following related tasks:

  • Send alerts when certain criteria are met
  • implement business rules on incoming data

For example, a user may input a task assigned to herself and set it to be due in three hours. Based on a business rule, when it is within one hour of its due time, the status would change from "pending" to "urgent."

This means that once per time period N, something needs to check the time of all pending tasks to see if they've entered the "urgent" threshold. Up to this point, I've only performed tasks like this using Windows Task Scheduler. (Create a batch file or EXE, have it run once every fifteen minutes.) I've been trying to suss out how the pros do it.

I'm under the impression that the preferred solution is to run a service to implement business rules. Here's what I don't understand: if I'm not using a utility like task scheduler, am I basically just running an infinite loop in one thread of my application that queries the service?

do
{
   myObject = myService.query();
   if (myObject.dueDate < Now() + 1 hour)
   {
       myObject.status = urgent
       //Update db
       //update view
       myService.fireAlert(myObject);
   }

   Thread.Sleep(60000);
}

This may be a broad, academic question. To be more specific, I'm coming at this with no knowledge of Windows Services. I think that's the direction I need to go, as I haven't really seen anything in the way of alternative ways to schedule code to run. Are there other possibilities?

For anyone who knows about SignalR, does that apply here?

tmoore82
  • 1,857
  • 1
  • 27
  • 48
  • 1
    It's an interesting question and it seems to be a tough one to get a solid answer for because "it depends". I asked a similar question on Programmers StackExchange (http://programmers.stackexchange.com/questions/194917/how-do-i-make-my-asp-net-application-take-an-action-based-on-time). SignlaR is only useful to you if users are actually on your application when events are triggered. – Rowan Freeman Oct 17 '13 at 21:57
  • Thanks @RowanFreeman. This would be an "always-on" application that users could be logged into at any time. In fact, it's more likely that events will be triggered while users are in the system than not. I figured this was an "it depends" question. I'm just totally flailing here. Total noob to this with no internal examples or guidance. :) What solution did you end up going with? – tmoore82 Oct 18 '13 at 12:32

0 Answers0