Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Sync item list between perl scripts, across servers (rename)

by tye (Sage)
on Nov 14, 2016 at 19:58 UTC ( [id://1175908] : note . print w/replies, xml ) Need Help??


in reply to Sync item list between perl scripts, across servers

For each system, create a subdirectory for use just by that system. When a thread picks up a filename, use rename to perform an atomic move of that file into the subdirectory for the system that the thread is hosted on. If the rename fails, then just skip that filename as the other system beat you to it.

Even better, when rename() fails, compare $! against ENOENT() from Errno. If you are on a Unix system, than you can check "man 2 rename" on your particular system to verify that ENOENT is the appropriate choice (but if you are on a Unix system, then I'm pretty sure it will be).

In the unlikely event that you are not on a Unix system and are not using MS Windows, then Perl's rename might not be atomic.

- tye