Schedulers in a Webfarm?

Topics: Administration, Core, General
Oct 18, 2013 at 5:27 PM
We are running into locking issues with background scheduler tasks... We think it might be related to the fact that we are in a farm environment..

is there a way to tell Orchard "only run schedules" on one server.

Thanks
Josh
Developer
Oct 18, 2013 at 5:32 PM
Have you tried Orchard.TaskLease module?
Oct 18, 2013 at 5:46 PM
So just looked at TaskLease module and um... How does it work? I mean I like the idea of it.. And I want to use it, but other than it being an IDependency interface how the heck does it actually work.. Beyond magic.... :-)
Coordinator
Oct 18, 2013 at 5:57 PM
The only usage right now is in the azure modules I think. But using it is simple, in your background task, call ITaskService.Acquire("MYTASKNAME", _clock.Now.AddDays(1)) and it will return a non null string if you are granted the right to do this action. If so another background task doing the same thing won't get a non empty string for one day. After that, if another background task does it, it will be granted the right to.
Oct 18, 2013 at 6:15 PM
And that makes since from what we are seeing..

Because we want our task to run very quickly (once a minute is fine) anyways, we are going to switch over to IBackgroundTask.Sweep... We already have node level filtering inside the task but we may refactor to use the TaskLease that way if a machine goes down in the cluster another machine can pickup the lease in a few minutes.

Thanks
Josh
Coordinator
Oct 18, 2013 at 6:25 PM
when the task is over, you can update it to reset the expiredUtc such that it's available to any other node right after that
Developer
Oct 18, 2013 at 9:33 PM
Beware that since TaskLease uses a DB record to store the lease it only makes sense if your tasks don't try to run simultaneously or you use ReadCommitted isolation level for DB access. Otherwise since the lease in the DB will only appear once the request/background task is completed, thus the transaction committed a simultaneously running process won't be able to know about it.

I solved this by using lock files in the Media folder. If Media is properly shared/replicated across nodes it provides somewhat what task lease does but regardless of transactions.