--- a/server/src/app/Console/Commands/IndexDocuments.php Thu Feb 09 17:22:58 2017 +0100
+++ b/server/src/app/Console/Commands/IndexDocuments.php Fri Feb 10 12:03:12 2017 +0100
@@ -250,17 +250,33 @@
return $res;
}, []);
- $labelsBnf = $this->bnfResolver->getLabels(
- array_unique(array_reduce(
- $sres,
- function($r, $so) {
- if($so['type'] === Utils::SUBJECT_TYPE_BNF) {
- array_push($r, $so['uri']);
- }
- return $r;
- },[]
- ))
- );
+ $labelsResolved = false;
+ $timeoutRetries = 0;
+ while(!$labelsResolved && $timeoutRetries < config('corpusparole.bnf_max_retries', 3)) {
+ try {
+ $labelsBnf = $this->bnfResolver->getLabels(
+ array_unique(array_reduce(
+ $sres,
+ function($r, $so) {
+ if($so['type'] === Utils::SUBJECT_TYPE_BNF) {
+ array_push($r, $so['uri']);
+ }
+ return $r;
+ },[]
+ ))
+ );
+ $labelsResolved = true;
+ } catch(BnfResolverTimeoutException $e) {
+ Log::warning('IndexDocument: Resolve label timeout, will retry');
+ $timeoutRetries++;
+ continue;
+ }
+ }
+ if(!$labelsResolved) {
+ Log::error("IndexDocument: Some bnf labels not resolved (retry timeout: $timeoutRetries).");
+ $this->error("\nError resolving bnf labels (retry timeout: $timeoutRetries). Stopping");
+ throw new \Exception("Error resolving bnf labels (retry timeout: $timeoutRetries). Stopping");
+ }
$labelsLexvo = $this->lexvoResolver->getNames(
array_unique(array_reduce(
$sres,
@@ -586,9 +602,11 @@
*
* @return int (1 if sucess, 0 if error)
*/
- private function indexBulk($docBodies)
- {
- $query_data = ['body' => []];
+ private function indexBulk($docBodies) {
+ if(empty($docBodies)) {
+ return;
+ }
+ $query_data = ['body' => []];
foreach($docBodies as $docId => $docBody){
$query_data['body'][] = [
'index' => [
@@ -665,6 +683,9 @@
$progressBar->setMessage($docId);
$progressBar->advance();
$doc = $this->documentRepository->get($docId);
+ if(is_null($doc)) {
+ continue;
+ }
$docBody = $this->getDocBody($doc);
if($noBulk) {
$this->indexOne($docId, $docBody);