Using IBackgroundTask in a Web farm deployment

Topics: Writing modules
Apr 27, 2012 at 4:18 PM

Hi, 

I am wondering if anyone has given any thought to how you could Implement a Background tasks that does database cleanup but in a WebFarm deployment. 

What I'd like to have it do is check every 15 minutes or so and Cleanup some expired data that might exist in a set of ContentRecords.  IBackgroundTask looks like a good way to implement this, but it would end up running on every web node right? There's potential that the query to determine what needs to be cleaned up could be and expensive operation, so if I wouldn't want 5 nodes in my web farm to all try the cleanup. Only one.

If this weren't in Orchard, I'd probably implement something in the web.config that would allow me to turn off the cleanup operation on all but one of the nodes. Is there some nice clean way to do something like this in Orchard? 

Gracias.

Ryan

 

Coordinator
Apr 27, 2012 at 6:24 PM

You should use the TaskLease module, whose responsibility is to acquire a named job within a farm, so that other nodes don't do the same thing.

Apr 28, 2012 at 2:17 AM

Thanks. I think that's perfect. :)