Managing Timeouts

Having a little trouble here. Hope one of you can help… I have a script that is 99% wonderful. Once a week it fails, and it fails in such a way that it doesn’t recover. The script times out, and presents a dialog that says it timed out, do I want to edit, or quit.

The step in question is accessing a database (Helix). It basically gets a number from a “Global” relation, which in Helix terms is a relation with 1 record, where one can store all sorts of parameters that you increment when you want to (and lots of other things). The story here is that its not pulling out 10K records, just one field value from 1 record.

I have a try and on error in there which should respond to any error that Helix might throw. However its not giving me an error its just timing out. I think what is happening is that the Helix Server is just busy and its not processing the request. This particular database wasn’t designed very well (not done by me) and it has the capability to get overwhelmed with the right series of events. I have a ‘with timeout’ statement in there, outside the try statement, but I don’t know how to manage things if it does timeout.

For example, try has an on error part that lets you do things when you get an error. Does timeout have a “on timeout” feature ? Is there a way to create one?

What do you folks do when you don’t get a response in a certain amount of time ?

TIA, Lenny

The with timeout block accepts a timeout interval expressed in seconds:

with timeout of nnn seconds
	...
end timeout

You should also be able to trap the timeout with a try-on error block. The error code you are looking for is -1712 (errAETimeout).

In these situations I use a ridiculously long timeout period and avoid the issue entirely. The default timeout period is 120 seconds which is fine for must things but is insufficient for commands with highly variable timings.

Let me see if I understand this correctly. One puts the try/end try on the outside of the “with timeout” and “end timeout”. Then if the timeout fails, it will fail with an error of -1712

I put it the other way around… that’s why no error…

Do I have this right?

Tx

IOW, would you expect this to return the right values?

tell application id "com.qsatoolworks.server"
		try
			with timeout of 120 seconds
				--grab the current global number
				set theResult to utilize {collectionName, myUser, myPassword, myRelation, myView} to retrieve records as list
				set theGlobalNumber to the helix record of item 1 of theResult
				set theNewNumber to (theGlobalNumber + fileCount)
			end timeout
		on error errMsg number errNum
			if (errNum is -1712) then
				set theDatetime to do shell script "date '+_%Y_%m_%d_%l-%M-%S-%p'"
				set logEntry to (theDatetime & "  Retrieve from Global timed out")
				set theResult to my writeToLogFile(logEntry)
			else
				set theDatetime to do shell script "date '+_%Y_%m_%d_%l-%M-%S-%p'"
				set logEntry to (theDatetime & "  Did not retrieve latest record number from Global")
				set theResult to my writeToLogFile(logEntry)
			end if
			return
		end try

Looks right to me, but I think Mark was suggesting a timeout of >> 120 sec:

Yes, I think you’ll want to use something like 10 minutes (600 seconds) or more.

Or, you also have the option of setting the timeout to something <120 seconds, for those cases when if a command doesn’t work right away, you don’t want the user to have to wait two minutes or more to be notified.

Also in your error handler/log you may want to specify how long the time out was:

set logEntry to (theDatetime & "  Retrieve from Global timed out after 2 minutes")

This issue has reared its ugly head again. I did what was suggested, I put a nice try statement in there with a larger-than-needed timeout.
The script failed with -1712 on the first handler. This happens to be a save command, for a Helix Server, something that might take a second or two. The person who wrote the database the Helix Server serves up isn’t very good at optimization, and he allows people to access very large lists of things, bogging down the server.
This morning, it did so again. Despite a timeout of an entire day, the Server was “unresponsive” for 9 seconds and the system crashed the AppleScript app.
In this instance, the app is crashed, there is no trapping of anything that’s going to happen.

Any ideas?

TIA, Lenny