0

I've run into this a few times recently at work. Where we have to develop an application that completes a series of items on a schedule, sometimes this schedule is configurable by the end user, other times its set in Config File. Either way, this task is something that should only be executed once, by a single machine. This isnt generally difficult, until you introduce the need for SOA/Geo Redundancy. In this particular case there are a total of 4 (could be 400) instances of this application running. There are two in each data center on opposite sides of the US.

I'm investigating successful patterns for this sort of thing. My current solution has each physical location determining if it should be active or dormant. We do this by checking a Session object that is maintained to another server. If DataCenter A is the live setup, then the logic auto-magically prevents the instances in DataCenter B from performing any execution. (We dont want the work to traverse the MPLS between DCs)

The two remaining instances in DC A will then query the Database for any jobs that need to be executed in the next 3 hours and cache them. A separate timer runs every second checking for jobs that need executed.

If it finds one it will execute a stored procedure first, that forces a full table lock, queries for the job that needs to be executed, checks the "StartedByInstance" Column for a value, if it doesnt find a value then it marks that record as being executed by InstanceX. Only then will it actually execute the job.

My direct questions are:

  1. Is this a good pattern?
  2. Are there any better patterns?
  3. Are there any libraries/apis that would be of interest?

Thanks!

Wjdavis5
  • 3,952
  • 7
  • 35
  • 63
  • Is one of the instances able to act as a scheduling master? pushing schedule updates to other instances? – Gusdor Jul 16 '14 at 11:58
  • Is there a reason you didn't pick an existing scheduling component like [Quartz](http://www.quartz-scheduler.net/)? – Dean Ward Jul 16 '14 at 12:00
  • @Gusdor - One could, yes, the goal here was to achieve the required functionality with as little effort as possible. We could do that but it would require a significant time investment to implement. Further I should add that the instances should not have to be aware of other instances. – Wjdavis5 Jul 16 '14 at 12:28
  • @DeanWard No reason - lack of time to execute (In a Professional Services Org) and we weren't given much notice to pull this off. I have (today) just started researching a reuseable pattern. – Wjdavis5 Jul 16 '14 at 12:29
  • Guessing you have a shared DB? Quartz does most of the things you've mentioned in your question. You'd need to use the [AdoJobStore](http://www.quartz-scheduler.net/documentation/quartz-1.x/tutorial/job-stores.html) to get things working in a clustered fashion and then decide what attributes to mark your jobs up with in order to prevent concurrent execution where applicable. – Dean Ward Jul 16 '14 at 12:37

0 Answers0