Ver código fonte

- add ELASTICSEARCH_REINDEX_ON_BOOT to env
- setup app:elasticsearchReindexOnBoot on config-loader.ts
- add reindex ES based on new env var on crowi/index.js
- investigate error index already exist
- add try catch condition to call normalizeIndices() in index.js because rebuildIndex() forced to throw error instead of call finally section
- add logger.info for reindexing process on boot
https://youtrack.weseek.co.jp/issue/GW-7639

LuqmanHakim-Grune 4 anos atrás
pai
commit
7da4768e40

+ 1 - 0
packages/app/.env.development

@@ -14,6 +14,7 @@ MONGO_URI="mongodb://mongo:27017/growi"
 ELASTICSEARCH_URI="http://elasticsearch:9200/growi"
 ELASTICSEARCH_URI="http://elasticsearch:9200/growi"
 ELASTICSEARCH_REQUEST_TIMEOUT=15000
 ELASTICSEARCH_REQUEST_TIMEOUT=15000
 ELASTICSEARCH_REJECT_UNAUTHORIZED=false
 ELASTICSEARCH_REJECT_UNAUTHORIZED=false
+ELASTICSEARCH_REINDEX_ON_BOOT=true
 USE_ELASTICSEARCH_V6=false
 USE_ELASTICSEARCH_V6=false
 HACKMD_URI="http://localhost:3010"
 HACKMD_URI="http://localhost:3010"
 HACKMD_URI_FOR_SERVER="http://hackmd:3000"
 HACKMD_URI_FOR_SERVER="http://hackmd:3000"

+ 18 - 1
packages/app/src/server/crowi/index.js

@@ -372,7 +372,24 @@ Crowi.prototype.setupPassport = async function() {
 };
 };
 
 
 Crowi.prototype.setupSearcher = async function() {
 Crowi.prototype.setupSearcher = async function() {
-  this.searchService = new SearchService(this);
+  const searchDelegatorLogger = loggerFactory('growi:service:search');
+
+  this.searchService = await new SearchService(this);
+
+  if (this.configManager.getConfig('crowi', 'app:elasticsearchReindexOnBoot')) {
+    searchDelegatorLogger.info('Reindex elasticsearch is running');
+    try {
+      this.searchService.rebuildIndex();
+    }
+    catch (err) {
+      // since rebuildIndex() will force to throw `error` in catch section and `finally` section won't be called,
+      // run normalize indices here anyway
+      this.searchService.normalizeIndices();
+    }
+  }
+  else {
+    searchDelegatorLogger.info('ELASTICSEARCH_REINDEX_ON_BOOT value is false, no reindex on boot');
+  }
 };
 };
 
 
 Crowi.prototype.setupMailer = async function() {
 Crowi.prototype.setupMailer = async function() {

+ 6 - 0
packages/app/src/server/service/config-loader.ts

@@ -268,6 +268,12 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type:    ValueType.BOOLEAN,
     type:    ValueType.BOOLEAN,
     default: false,
     default: false,
   },
   },
+  ELASTICSEARCH_REINDEX_ON_BOOT: {
+    ns:      'crowi',
+    key:     'app:elasticsearchReindexOnBoot',
+    type:    ValueType.BOOLEAN,
+    default: true,
+  },
   USE_ELASTICSEARCH_V6: {
   USE_ELASTICSEARCH_V6: {
     ns:      'crowi',
     ns:      'crowi',
     key:     'app:useElasticsearchV6',
     key:     'app:useElasticsearchV6',