Hi,

On 16-9-2011 10:40, Andre Flitsch wrote:
I have the problem that my client is impatient, and sometimes cannot
wait for the automatic import to run, so then they run it manually then
we have some sort of collision in the database. So i need to stop them
from messing up everything with their over excited clicking finger.

The usual old fashioned way to prevent parallel runs is to use a lock file.
At the beginning of your job you check if the lock file exists. If it exists and it is not too old you simply stop (the check for the age prevents crashed jobs from blocking future jobs forever). Then you can create a lock file and run the job itself. At the end of the job you delete the lock file.

If you do this lock file juggling in the code which is shared between the automatic and the manual job (or use the same lock file for both) it also helps with your problem.

$lockfile = PATH_site . 'typo3temp/tx_myext.lock';
        // Check if job is already running
if (@file_exists($lockfile)) {
                // If the lock is not older than 1 hour, skip job
        if (filemtime($lockfile) > (time() - (60*60))) {
                // skip, it's already running
                //****
        } else {
                // continue, but it's an old lock file, report that
                // job took too long or crashed
                //****
        }
}
touch ($lockfile);
        // do actual job
@unlink ($lockfile);

An alternative solution might be to do the entire import in a single database transaction. That would at least solve the database collisions.

--
Kind regards / met vriendelijke groet,

Jigal van Hemert.
_______________________________________________
TYPO3-english mailing list
TYPO3-english@lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-english

Reply via email to