in reply to CGI daily 'cleanup' task

Wow .. 33%. That's pretty high. After three accesses, the odds are even that you will have run the cleanup. Your choice .. You can use a lock file. This is duplicating what cron does, so you may as well use their format to store tasks. I had a quick look at CPAN but didn't find anything that will handle cron format task list, but that's probably a good way to go, depending on the complexity of the task timing.

--t. alex
but my friends call me T.

Replies are listed 'Best First'.
Re: Re: CGI daily 'cleanup' task
by twerq (Deacon) on Aug 28, 2002 at 14:33 UTC
    Does the lock file exist? If so, someone else is already doing a cleanup.

    This seems like a good solution for making sure I'm the only agent running...

    Wow .. 33%. That's pretty high. After three accesses, the odds are even that you will have run the cleanup. Your choice ..

    Let me clarify -- that was just a number I quickly threw out there, but basically I was thinking that there should be a 33% chance that the script will check to see if it needs to run a cleanup process. Which is something like:
    if (33% chance) { if (it has been a day or more since last cleanup) { // Do our thing } }
    Although now I'm going to have to leave another little file lying around letting my script know when the last cleanup happened. . . starting to seem pretty hacky. Maybe I should just use a scheduler :)

    FYI -- I'm building this web application on trusted servers, but have no idea where it's going to be run once I'm done, which is why I'm trying to keep away from relying on cron, and relying on sysadmins to set things like that up properly.

    also -- the cleanup is actually going to be doing post-due transactions from a DB.
    --twerq
      It sounds like you want a mechanism whereby you do some cleanup if it's been at least 'n' hours since the last cleanup, or if it's a new calendar date since the last cleanup, or if a cleanup's never been done.

      It makes sense not to rely on cron if you don't know where the application is going to be rolled out -- I was only suggesting sticking to the cron format if there was a module that handles that already. Otherwise, go crazy and write your own protocol.

      --t. alex
      but my friends call me T.