Home   Archive   Permalink



safe-save function

@nick: I used this function in one of my cgi scripts, to be sure the data saved to file even there is a concurrency (I know it is a soooo rare situation if server is not heavily loaded)
    
safe-save: func [file [file!] data] [
     loop 3 [
         if attempt [write/append file data wait 0.3 true] [break/return true]
     ]
]
    
if none? safe-save %file data [error-saving-data]
    
might be useful for someone.

posted by:   Endo     11-Jun-2010/5:40:43-7:00



I can use that :)

posted by:   Nick     11-Jun-2010/9:51:26-7:00



I can vouch for this approach.
    
We use very similar code on all the CGIs at REBOL.org. Deploying it reduced very rare (perhaps once a year) write failures to (so far, in several years) none at all.
    
We have similar read-safe and delete-safe functions too.

posted by:   Sunanda     12-Jun-2010/16:52:32-7:00



Really? I'm glad I'm on the right way :)

posted by:   Endo     12-Jun-2010/18:36:48-7:00