views:

1313

answers:

10

What are the different approaches for creating scheduled tasks for web applications, with or without a separate web/desktop application?

+2  A: 

I think Stack Overflow itself is using an ApplicationCache expiration to run background code at intervals.

Eric Z Beard
+2  A: 

If you're on a Linux host, you'll almost certainly be using cron.

ceejayoz
+1  A: 

Under linux you can use cron jobs (http://www.unixgeeks.org/security/newbie/unix/cron-1.html) to schedule tasks.

Use URL fetchers like wget or curl to make HTTP GET requests.

Secure your URLs with authentication so that no one can execute the tasks without knowing the user/password.

Marcel
+1  A: 

I think Windows' built-in Task Scheduler is the suggested tool for this job. That requires an outside application.

Nick
A: 

This may or may not be what you're looking for, but read this article, "Simulate a Windows Service using ASP.NET to run scheduled jobs". I think StackOverflow may use this method or it was at least talked about using it.

Jason Shoulders
+2  A: 

If we're talking Microsoft platform, then I'd always develop a separate Windows Service to handle such batch tasks.

You can always reference the same assemblies that are being used by your web application to avoid any nasty code duplication.

Ian Nelson
A: 

A very simple method that we've used where I work is this:

  1. Set up a webservice/web method that executes the task. This webservice can be secured with username/pass if desired.
  2. Create a console app that calls this web service. If desired, you can have the console app send parameters and/or get back some sort of metrics for output to the console or external logging.
  3. Schedule this executable in the task scheduler of choice.

It's not pretty, but it is simple and reliable. Since the console app is essentially just a heartbeat to tell the app to go do its work, it does not need to share any libraries with the application. Another plus of this methodology is that it's fairly trivial to kick off manually when needed.

Daniel Auger
+3  A: 

Jeff discussed this on the Stack Overflow blog - http://blog.stackoverflow.com/category/aspnet/

Basically, Jeff proposed using the CacheItemRemovedCallback as a timer for calling certain tasks.

I personally believe that automated tasks should be handled as a service, a Windows scheduled task, or a job in SQL Server.

Under Linux, checkout cron.

Terrapin
+1  A: 

Use URL fetchers like wget or curl to make HTTP GET requests.

Secure your URLs with authentication so that no one can execute the tasks without knowing the user/password.

You can also tell cron to run php scripts directly, for example. And you can set the permissions on the PHP file to prevent other people accessing them or better yet, don't have these utility scripts in a web accessible directory...

Flubba
A: 

Java and Spring -- Use quartz. Very nice and reliable -- http://static.springframework.org/spring/docs/1.2.x/reference/scheduling.html

Dustin