in reply to CGI daily 'cleanup' task

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...