Commit f28de9b6d5000b1a20842586c10739eeb9369d5b

Authored by Megan
1 parent 95ff3c27

Added a lock file to the document processor to prevent multiple occurrences of t…

…he indexing taking place at the same time, which could cause race conditions.

Committed by: Megan Watson
search2/documentProcessor/documentProcessor.inc.php
... ... @@ -144,6 +144,16 @@ class DocumentProcessor
144 144 global $default;
145 145 $default->log->debug('documentProcessor: starting');
146 146  
  147 + // Check for lock file to ensure processor is not currently running
  148 + $cacheDir = $default->cacheDirectory;
  149 + $lockFile = $cacheDir . DIRECTORY_SEPARATOR . 'document_processor.lock';
  150 +
  151 + if(file_exists($lockFile)){
  152 + // lock file exists, exit
  153 + $default->log->debug('documentProcessor: stopping, lock file in place '.$lockFile);
  154 + return ;
  155 + }
  156 +
147 157 if($default->enableIndexing){
148 158 // Setup indexing - load extractors, run diagnostics
149 159 if($this->indexer->preIndexingSetup() === false){
... ... @@ -160,6 +170,10 @@ class DocumentProcessor
160 170 return ;
161 171 }
162 172  
  173 + // indexing starting - create lock file
  174 + touch($lockFile);
  175 +
  176 +
163 177 // Process queue
164 178 foreach($queue as $item){
165 179  
... ... @@ -198,6 +212,11 @@ class DocumentProcessor
198 212 // update the indexer statistics
199 213 $this->indexer->updateIndexStats();
200 214  
  215 + // Remove lock file to indicate processing has completed
  216 + if(file_exists($lockFile)){
  217 + @unlink($lockFile);
  218 + }
  219 +
201 220 $default->log->debug('documentProcessor: stopping');
202 221 }
203 222  
... ...