[Freeswitch-users] FreeSWITCH load CDR CSV to Mysql, theoretical problem?

Paul Cupis paul at cupis.co.uk
Wed Jan 25 22:06:33 MSK 2012


On 25/01/12 13:25, Henrik Aagaard Sørensen wrote:
> What if the job suddenly takes more than 5 minutes to complete and
> another job start, doing the same thing.
>
> Couldn't that be a problem and can it be fixed?

Use Perls Fcntl module to ensure the program can only be running once - 
if a second instance starts it will quit immediately and the next 
scheduled run will pick up the remaining files.

Of course, if this happens to often you will take a long time to catch 
up with the importing.

At the beginning of the script (after 'use File::Copy;') add:


use Fcntl qw(:flock);
unless (flock(DATA, LOCK_EX|LOCK_NB)) {
     exit;
     print "$0 is already running. Exiting.\n";
     exit(1);
}


and at the very end add:

__DATA__
This exists so flock() code above works.
DO NOT REMOVE THIS DATA SECTION.



Regards,



Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list