Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hmm. Well, if I had to do this, and I have to come clean now, I know nothing of CGI::Application (I will check it out in a few minutes), so coming from this angle, I'd do:

  • If we become a cleanup process, somehow make sure we're the only one (-- how can I do this?)
  • I'd do this one or both of two ways. 1) I'd have the code create a pidfile (assuming it doesn't fork so there is no parent to worry about if dealing with a child process). Once the process ends it would remove the pid file. I'd use that pidfile to see if there is a process running already. I would of course not only check if the pidfile exists but I'd check for the pid that is contained in that pidfile to see if it is a valid running pid.
    2) I'd simply check the process table to see if a pid exists for the program that I need to check if running.

  • Cleanup process checks to see if there are any tasks past due, takes care of them and quietly exits.
  • Ok. Now, IIUYC (if I understand you correctly =), you want to try and schedule the clean up without using cron. Well, according to what you stated, why can't you create a tmp file someplace that your script checks for overdue tasks that need to be cleaned up? Tasks get placed in the tmp file with a timestamp. You would check the timestamp of the completed task and then use a time table for when that task becomes overdue for cleaning. Thus, if a task completed at 0530 HRS and your table says that for *that* particular task cleanup should be done 4 hours afterward, then your script is smart enough to know that at 0930 HRS cleanup for that task should be performed. Once the cleanup is completed, don't forget to take that entry out of the tmp file.

    You can also simply place something in the code that makes the script do the cleanup after a certain time per day or a certain day of the week. Meaning, you place something in the script or a config file saying that cleanup must not be done until 0200 HRS everyday. The script kicks off all day long every hour but it won't perform the cleanup until sometime between 0200 and 0300 of the current day.

    Anyway, I hope I understood your questions. If I were in your shoes and I understood your questions properly, these are a couple of ways I would have thought about tackling the chore.

    Generally, I prefer to stay away from temp files but if this program isn't a daemon then I believe temp files would be the best route to go.

    _ _ _ _ _ _ _ _ _ _
    - Jim
    Insert clever comment here...

    In reply to Re: CGI daily 'cleanup' task by snafu
    in thread CGI daily 'cleanup' task by twerq

    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post; it's "PerlMonks-approved HTML":

    • Are you posting in the right place? Check out Where do I post X? to know for sure.
    • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
      <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
    • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
    • Want more info? How to link or or How to display code and escape characters are good places to start.
    Log In?

    What's my password?
    Create A New User
    Domain Nodelet?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (5)
    As of 2022-08-12 18:11 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found