Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do Time based / scheduled events in .NET?

I need to offer scheduling of actions/events, in our web site. A crap analogy could be a calendar system, where a person adds a calendar item and when the date/time has been 'hit', then some logic (eg calculate a report) is fired.

I could be having hundreds and even thousands of scheduled events that are entered by my clients. When a client enters something to get scheduled, I will save that info to the database. Then i'm guessing i'll added an event/job somewhere, which will contain the database table primary key. when the event is to be fired, i'll grab that info from the db, then do the logic. done.

What are some common solutions to handle this?

I'm using .NET 3.5 SP1. DB is Sql Server 2008. UI will be webbased though.

I wasn't sure if people use MSMQ? Or something built into Sql Server? Or some open source library (eg. Quartz.NET) with an NT Service. Server will be windows 2008 standard edition.

Also - please not suggestions to use a cron job equivalent or any command line scripts, etc.

Finally, and this is a secondary objective .. i'd love to throw this up onto azure for shiz and giggles ... so is the also possible? it's only a wish list idea. I would prefer to do it on a dedicated box if the solution is easier, than using Azure.

cheers :)

edit: Logic to process when an event is required to be fired, are background jobs. No UI required.

like image 260
Pure.Krome Avatar asked Jun 19 '09 01:06

Pure.Krome


2 Answers

Workflow Foundation can do this. Use a Delay activity, set the TimeSpan to (DesiredTimeOfExecution - Now). For larger scale systems, set UnloadOnIdle to true, and the pending workflows will be persisted until needed.

Here's a very simple example of the Delay Activity.

WF is Free, included as part of the .NET Framework 3.0.

like image 97
Cheeso Avatar answered Oct 27 '22 01:10

Cheeso


Quartz.NET probably could also handle these requirements quite well. The benefits I see are in various ways of setting the scheduler (CronTrigger + calendars) and the ability to have your jobs in small units of testable code (jobs).

Quartz.NET also gives you the needed distribution and fail-over with clustering features. One nice feature is also per-trigger configurable misfire handling setups that give you opportunity to react to misfires and scheduler down-time.

SQL Service Broker seems to have the benefit of no polling, I wonder whether that will ever be the issue though, broker has the disadvantage of sounding a bit complicated ( at least from the description I read above).

Just my biased $0.02.

like image 25
Marko Lahma Avatar answered Oct 27 '22 00:10

Marko Lahma