Quantcast

Maximum PC

It is currently Thu Jul 24, 2014 10:19 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Cyclically execute processes till they succeed?
PostPosted: Thu Dec 18, 2008 6:56 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
I have a list of functions that I want to "try" a number of times (say 3) before I give up and move on.

I am trying to build some redundancy into a data synchronization process that runs every 6 hours. I don't want a network hiccup or something to cause a time out and then have the data be out of date for another 6 hours. Currently there is nothing for retrying, and if the database connection fails or times out, it won't continue.

I don't have plans to re-create the entire process that I have, but I do want to develop some standard I can follow....

Here is a pseudocode implementation of what I want to do:

Code:
ListOfFucntions.Add(FunctionA)
ListOfFucntions.Add(FunctionB)
ListOfFucntions.Add(FunctionC)
...

while ListOfFunctions has length > 0 {
     for each function in ListOfFunctions {
          if (function.attempts < 3){
               function.execute
          }
          else{
               ListOfFunctions.Remove(function)
               // Possibly add to a list of failed processes and/or log failure
          }
          if (function.success){
               ListOfFunctions.Remove(function);
          }
     }
}

function.execute{
     try{
          Do Stuff
          function.success = true
     }
     catch{
         function.attempts++
     }
}


Can anybody provide some thoughts on this? I haven't exactly figured out how to go about this. It will be written in C# using .NET 2.0.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 9:07 am 
Little Foot
Little Foot
User avatar

Joined: Thu Jul 08, 2004 3:41 pm
Posts: 123
Location: St. Louis, MO USA
What has done well for me is to use a lock file at the source of the data. And this method assumes that any failure will cause a complete rollback at the target. Kick off the process and check the lockfile associated with the data file. If its not locked, set the lock and process the data. At completion, set the lockfile unlocked, and terminate your process normally. This has the side benefit of not allowing two processes to work on the data at the same time. If your process fails, set the lock file unlocked and kick off your process again.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 9:37 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
I am not sure how that would work.

We have two databases on servers and then the client. The backend system database gets data exported to a "staging" database that tracks when items changed. This is then copied down to the client based on the time stamps.

Mostly what I am concerned about is time out exceptions or connection interruptions.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 12:56 pm 
Little Foot
Little Foot
User avatar

Joined: Thu Jul 08, 2004 3:41 pm
Posts: 123
Location: St. Louis, MO USA
Implied in my previous post is that you simply keep trying until successful. That's what the lock file is all about.

Anyway. what are the two databases? Oracle, something else? If they are both the same, and both are Oracle, there's a much better way to do this.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 2:36 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
OS-Wiz wrote:
Implied in my previous post is that you simply keep trying until successful. That's what the lock file is all about.

Anyway. what are the two databases? Oracle, something else? If they are both the same, and both are Oracle, there's a much better way to do this.
One is Oracle and the other is MS Sql 2005.

Can you give a little bit more of an example on your idea then? I must have read it wrong. I also don't necessarily want it to try forever either.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 4:16 pm 
Little Foot
Little Foot
User avatar

Joined: Thu Jul 08, 2004 3:41 pm
Posts: 123
Location: St. Louis, MO USA
One of the big problems with interfaces like this is when someone goofs and kicks off two interface jobs (your process) at, or nearly at, the same time. Don't laugh yet, I've seen this happen several different places with the obvious results -- either double loaded data, or partially loaded data. The lock file prevents this. The first thing the process does is attempt to set the lock in the lockfile. If it can, all is well, continue processing. If it is locked, three possibilities exist. 1 Two processes were kicked off, so the one that discovers the lock terminates itself. 2 A previous process may have completed the data load but failed just prior to unlocking the lockfile. 3. A previous process started, but didn't complete the data load, nor unlocked the lock file. Whenever a process discovers a lock in the lock file, notify whomever is resposible (at least two individuals), with whatever method (email?) so they can fix the issue. I don't know MS SQL 2005, but do know Oracle. Oracle will return a failed connection message to the caller (your process) after reconnecting and will usually rollback any work done, if any. So, your process should check for these connection failure messages and try again. I would wait n minutes before reattmepting and reattempt many more than just 3 times -- is it not important that you load the data? You might also ping SQL 2005 and Oracle occassionly to see if the connection still exists. You are working a tough problem, so check the SQL 2005 and Oracle messages you need to be looking for and plan for the worst.

P.S. This is hard to explain in a forum like this, so if I'm not clear, please ask questions.
P.S.S Also, this will be much easier to do in a shell script and a PL/SQL package.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group