Monday, December 04, 2006

Some Simple Automation

I've been at my new job for just over two months now. There's been much to learn, and lots to do, and still more coming, as we signed another customer and somehow I have to figure out how to continue doing work for the previous while starting up the new. Normally, this hasn't been a big problem for me in my career, but usually there are more other people to do pieces of it than there are now. I know that will change over time, and, no, it's not as if I'm flying solo.

One of the things that has brought me great pleasure, especially at this very moment, has been the benefits of some simple automation scripts. We have a very sophisticated caching system, but at present the cache seeding has to be done using scripts. When I came on the scene, my co-worker Manish had already created a simple batch file for kicking off a scripting run. It worked, basically, and was a good starting point.

I have had to do a lot more seeding than he has, though, so I have worked on this script from time to time over the last month or so. The problem is that our tomcats occasionally lose their connection to the database in the middle of a query in the middle of the seed list. This is bad when it's 11pm and Dylan's just gone off to bed. The first major modification was to have it check the log file for a certain type of exception and delete the log and start over if it found it. Unfortunately, that loses me any information about how long things are taking.

The next major modification was a way of saving the log file after each failure and appending the next one when it either failed or finished. It also records the time into the file at the beginning and end and after each failure, so I can see the total elapsed time as well as how often we're losing our DB connection. This was cool, except I had a couple of typos that meant that by the time the process finished I wound up with no log at all! It took more than a week to get around to figuring that one out.

A couple of days ago, I realized that there are now three different ways (well, eventually two - one for my local environment and one for production environments, but I'm converting production from one way to another, so there are three right now) of accessing the engine that runs the queries for me. So I changed the script to look for the engine.

Also a few days ago, the engine was enhanced to allow me to supply the target server on the command-line. This seemed really cool, until I discovered that it works for some operations and not others. I need to file a defect on the later, and when it is fixed, it will be very cool. In the meantime, I changed the script to allow me to supply the server directive on the command-line if I'm not including it in the seed list.

And today, as I have to do some major re-aggregating and re-caching because of some minor tactical oversights, I learned how to make a Windows batch file spawn another window, and have created an ancillary script. This script, given a wild-card (and an optional server directive, of course) will spawn the run_seed batch file on all the files matching the wildcard. For tonight, there are 14. That means as soon as I kick that off, I'm going to bed. Because I essentially know that it WILL finish, barring any major system problems at our colo facility.

Of course, there's some check-up I have to do on what's finishing now, and some other prep. But maybe I don't have to stay up all flippin' night.

No comments: