diff -r ac3dc090e987 -r f2a40bbc27f6 server/src/app/Console/Commands/ImportCocoonRDF.php --- a/server/src/app/Console/Commands/ImportCocoonRDF.php Fri Nov 13 16:45:27 2015 +0100 +++ b/server/src/app/Console/Commands/ImportCocoonRDF.php Tue Nov 17 13:11:55 2015 +0100 @@ -12,6 +12,8 @@ class ImportCocoonRDF extends Command { + const INSERT_TIMEOUT_RETRY = 5; + /** * The console command description. * @@ -58,6 +60,8 @@ $progressBar = $this->output->createProgressBar($recs->getTotalRecordsInCollection()); $progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% - %message%'); + $insertTimeouts = 0; + foreach ($recs as $item) { $identifier = (string) $item->xpath('/record/header/identifier')[0]; @@ -72,6 +76,7 @@ $progressBar->advance(); $docUri = config('corpusparole.cocoon_doc_id_base_uri').substr($identifier, strlen(Config::get('corpusparole.cocoon_doc_id_base'))); + $resDocs = $gs->query("ASK WHERE { GRAPH <$docUri> { ?s ?p ?o }}"); if(!$resDocs->getBoolean()) { $docLoaded = false; @@ -108,8 +113,23 @@ //TODO: treat errors $subjects = $doc->resources(); $subject = reset($subjects)->getUri(); - //TODO: exceptions ? but if pb on insert probably we have to fail anyway - $gs->insert($doc, $subject); + try { + $gs->insert($doc, $subject); + } + catch(\Exception $e) { + // just log not much we can do here... + $this->error("\nError on insert $identifier ($docRdfUrl) : $e"); + Log::error("Error on insert $identifier ($docRdfUrl) : $e"); + $code = $e->getCode(); + $message = $e->getMessage(); + if($e instanceof EasyRdf\Exception && stripos($message, 'timed out')>=0 && $insertTimeout<= ImportCocoonRDF::INSERT_TIMEOUT_RETRY) { + $this->info("\nThis is a timeout, we continue."); + Log::info("This is a timeout, we continue."); + $insertTimeouts++; + continue; + } + throw $e; + } } } $progressBar->setMessage("finished");