Execution of a "long" script

kee nethery kee at kagi.com
Mon Aug 11 14:18:24 EDT 2014


I have a bunch of long running scripts. I structure them so that they pause between cycles. By that I mean, if I am processing a bunch of files, I might have a field where I list all the files and then I trigger a script that processes the first unprocessed file in the list. When there are no unprocessed files, it halts because it is done.

When a file is processed, I mark it in the list and then the very next thing I do is send a message in (for example) 5 seconds, to run that script again. For that 5 seconds nothing happens and presumably “things” reset to an idle state before going after the next file. It keeps doing this until all the files are processed.

I have scripts that essentially run for weeks at a time.

The one feature I add into all my scripts is a safe exit from whatever it is doing. Within all my loops I have:

if optionkey is down then
   exit repeat
end if

I put these all throughout my code so that if I need to halt, it does so safely. In the file example, perhaps in a beginning section I just exit out of the script. Perhaps in a section after an hour of processing, I let it finish and then don’t trigger the send message in 5 seconds to do it again.

Finally, In long running scripts I find it is essential to provide a visual indication of where the script is. I try to have something in the interface change more frequently than once a minute so that I know it is still running and not lost in some loop. Plus, if it stays with some indicator for a really long period of time, I know that is where I need to add a debug statement and figure out why it is taking so long there.

Kee Nethery



More information about the use-livecode mailing list