Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: CGI daily 'cleanup' task

by talexb (Chancellor)
on Aug 28, 2002 at 13:44 UTC ( #193452=note: print w/replies, xml ) Need Help??


in reply to CGI daily 'cleanup' task

    Every invocation of the CGI has a 33% chance of forking a 'cleanup' child process
Wow .. 33%. That's pretty high. After three accesses, the odds are even that you will have run the cleanup. Your choice ..
    If we become a cleanup process, somehow make sure we're the only one (-- how can I do this?)
You can use a lock file.
  • Does the lock file exist? If so, someone else is already doing a cleanup.
  • Create a randomly name lock file. Do more than one of them exist? If so, continue only if yours was the first one created; otherwise, delete the lock file .. someone else is already doing a cleanup.
  • Do your cleanup, delete the lock file.
    Cleanup process checks to see if there are any tasks past due, takes care of them and quietly exits
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://193452]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2022-08-12 18:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?