in reply to automating a task

....or create anything else to go wrong?

If I were writing that, I would allow for the database going off-line while the program sleeps.

This is important if you are doing maintenance work. $dbh may no longer be valid when you wake up. I would put some code to try to re-connect (with sleep/retry) if the current connection is invalid.

I would also add some escape route - reporting the catastrophe, in case of "repeated failure" for an "extended period", for some definition of those terms.

     Potentia vobiscum ! (Si hoc legere scis nimium eruditionis habes)

Replies are listed 'Best First'.
Re^2: automating a task
by Anonymous Monk on May 31, 2009 at 20:59 UTC
    Ok, so this would suffice:

    #shut off website... my $_sleepTime = (60 * 5); my $_notifyTime = time() + (60 * 60); my $_maxTime = time() + (60 * 60 * 6); until($dbh->selectrow_array(qq{select `value` from `pagevars` where `n +ame` = "eom_process"}) eq "ready") { $dbh->disconnect(); sleep($_sleepTime); $dbh = RWC::Sess::connect(); if(time() >= $_notifyTime) { # Send an email notifying of still not running... $_notifyTime = time() + (60 * 60);# Reset timer } if(time() >= $_maxTime) { # Send notice of final disconnection and exiting # to manually fix... send this notice to my cell # phone to alarm me # Disconnect from database.... if connected if($dbh) { $dbh->disconnect(); } exit; } }

    that makes logical sense... so while it is sleeping it does not use any memory right? what if it does take all that time everytime it starts again does it keep building upon the memory it had and then get larger and larger? or does the disconnecting from the database reduce the memory on the fly, even before perl is exited?

    thanks again,
    Richard

      ...so while it is sleeping it does not use any memory right?

      No, not right: it still reserves whatever memory it had allocated when the sleep starts at line 7 (which includes a small amount of memory required for the countdown tracking) -- and it still uses a few CPU cycles to do the tracking.

      what if it does take all that time everytime it starts again does it keep building upon the memory it had and then get larger and larger?

      There's no obvious (to me) reason for the memory useage to grow when the sleep time expires. However, you're disconnecting from the database before the sleep, so you'll need someone with a better handle on garbage collection and memory release to get a knowledgeable reply. Note, though, that "starts again" is perhaps better phrased "resumes." sleep does not force reinitialization of anything, except as forced to do so by your code.

      ...reduce the memory on the fly, even before perl is exited?

      Likewise, heed what wiser heads say about this, but my understanding is that that's not likely.