Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Application Design Issue

by perlCrazy (Monk)
on Feb 04, 2008 at 11:16 UTC ( #665933=perlquestion: print w/ replies, xml ) Need Help??
perlCrazy has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
Need some advice/suggestions regarding design of application.
I have written one application that builds the data server.
Application contains one main perl script that uses 2-3 modules and calls the subroutine from those modules. It does everything right.
New functionality we want to implement in this application :
if user runs the script and it fails to any step
(currently there are 8-10 steps are there that is being called sequentially) lets say 3rd step,
user will get the error and next time he will run again then script should start the processing from 4th steps, not from step 1.
Please advice/suggest. This will be great help.

Comment on Application Design Issue
Re: Application Design Issue
by stiller (Friar) on Feb 04, 2008 at 11:32 UTC
    You need an easy way to keep score, I have used a system where I

    mv step_1_started step_1_done

    and mv step_1_done step_2_started ...

    unlink step_8_done

    Now you can

    if (-e step_1_done)
      I am creating step1_file that indicates that step1 has been executed successfully.
      If any error comes then that step${n}_file will not be created.
      How this to implement in main script.
      Are you indicating something like, create label and then use GO TO ?
        I would read in (with glob) the step_X_done file. Read its number, or 1 into a variable $already_done

        for my $todo ($already_done .. $final_step){ do_step1() if $todo == 1; do_step2() if (-e step_1_done);
        then wrap the code for each step in separate subs.

        Now you can manually delete a "step-file" to have the job start from scratch, or at some spesific step, if you ever need that.

Re: Application Design Issue
by apl (Monsignor) on Feb 04, 2008 at 12:36 UTC
    Similarly, you could have a single file that contained the last successfully processed step. When the process restarts, read the one file and process accordingly (i.e. the value is '3', now process Step 4).
Re: Application Design Issue
by TedPride (Priest) on Feb 04, 2008 at 13:55 UTC
    Create a new module with a die wrapper, that stores the last place the user was at. It doesn't matter what the mechanism is - you can add / remove file markers, or you can store the position in a database (I recommend this for sure if you may run more than one user simultaneously) - but the wrapper will allow you to exit from any point with the desired action and only have to give a simple function call myDie($user, $position, $error)

    Then of course you'll have another function that you run at the start that picks up the last user position, which is then used with conditionals to skip the parts you already covered. myPosition($user) Again, the mechanism isn't important, you can swap it around later if you feel like it.

Re: Application Design Issue
by jdporter (Canon) on Feb 04, 2008 at 16:24 UTC

    Wouldn't you normally want to resume processing from the failed step (i.e. step 3)? I would think the objective would be for every step to have been executed successfully. No?

    A word spoken in Mind will reach its own level, in the objective world, by its own weight
Re: Application Design Issue
by plobsing (Friar) on Feb 04, 2008 at 23:34 UTC
    Sounds like a job for dump and undump.

    If only I could get them to work.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://665933]
Approved by andreas1234567
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-07-28 06:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (189 votes), past polls