Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am thinking of adding "crash immunity" (so to speak) to some of my code.

What I imagine is some capability of the script to track where it left off, as a result of say lost network connection.
And when the script is run again it will continue doing whatever it was doing when it was interrupted.

The script has to maintain some kind of "savepoints", I guess, to be able to resume execution from a sane state.

So in addition to knowing where in the script we were, we have to know about open files, file pointers, variables...

While this all sound a bit complex, I have in fact implemented a very simple version of this idea. When the program is terminated in a controlled way (in my case by setting an event) it can manage a restart from that point later.

But I would like to work more on this.
And I am now looking for pointers to techniques for dealing with this issue.

Thanks in advance for all suggestions,
L

Replies are listed 'Best First'.
Re: Crash immunity
by adrianh (Chancellor) on Oct 26, 2003 at 18:09 UTC

    You might find Attempt of interest.

    Basically my approach would be to wrap code that might fail in an eval and store whatever state I need so I can restore it on failure.

Re: Crash immunity
by pg (Canon) on Oct 26, 2003 at 19:03 UTC

    What I did is carefully analyze "unit of work" in my system, and number my execution steps.

    When you start your script always pass "step' as one of the parameter (or some other way, to pass the step number to the script, for example storing in a database table etc). the script just start itself from the given step.

    At the beginning the step numbers might be whole bunch of zeros. When your script is running, it has to update the step numbers periodically, when a "unit of work" is completed sucessfully.

    "Step number" is not neccessary to be one number, actually it can be a set of number (for me usually two or three numbers), so you can have sub-steps within a step. This is simple and very useful, most of my programs are restartable.

    The most important thing here is to identify your "unit of work".

Re: Crash immunity
by Anonymous Monk on Oct 27, 2003 at 14:14 UTC
    Thank you for your suggestions.
    I will try it out.

    L