Browse Source

Добавлена периодическая проверка изменений inpx
для автоматического пересоздания поисковой БД

Book Pauk 2 years ago
parent
commit
fe0f272acc
3 changed files with 33 additions and 0 deletions
  1. 1 0
      server/config/base.js
  2. 1 0
      server/config/index.js
  3. 31 0
      server/core/WebWorker.js

+ 1 - 0
server/config/base.js

@@ -22,6 +22,7 @@ module.exports = {
     maxFilesDirSize: 1024*1024*1024,//1Gb
     queryCacheEnabled: true,
     cacheCleanInterval: 60,//minutes
+    inpxCheckInterval: 60,//minutes
     lowMemoryMode: false,
 
     webConfigParams: ['name', 'version', 'branch', 'bookReadLink'],

+ 1 - 0
server/config/index.js

@@ -10,6 +10,7 @@ const propsToSave = [
     'maxFilesDirSize',
     'queryCacheEnabled',
     'cacheCleanInterval',
+    'inpxCheckInterval',
     'lowMemoryMode',
     'server',
 ];

+ 31 - 0
server/core/WebWorker.js

@@ -53,7 +53,9 @@ class WebWorker {
                     maxSize: this.config.maxFilesDirSize,
                 },
             ];
+
             this.periodicCleanDir(dirConfig);//no await
+            this.periodicCheckInpx();//no await
 
             instance = this;
         }
@@ -489,6 +491,35 @@ class WebWorker {
             ayncExit.exit(1);
         }
     }
+
+    async periodicCheckInpx() {
+        const inpxCheckInterval = this.config.inpxCheckInterval;
+        if (!inpxCheckInterval)
+            return;
+
+        while (1) {// eslint-disable-line no-constant-condition
+            try {
+                while (this.myState != ssNormal)
+                    await utils.sleep(1000);
+
+                log('check inpx file for changes');
+                const newInpxHash = await utils.getFileHash(this.config.inpxFile, 'sha256', 'hex');
+
+                const dbConfig = await this.dbConfig();
+                const currentInpxHash = (dbConfig.inpxHash ? dbConfig.inpxHash : '');
+
+                if (newInpxHash !== currentInpxHash) {
+                    log('inpx file changed, recreating DB');
+                    await this.recreateDb();
+                }
+            } catch(e) {
+                log(LM_ERR, `periodicCheckInpx: ${e.message}`);
+            }
+
+            //await utils.sleep(inpxCheckInterval*60*1000);
+            await utils.sleep(10000);
+        }
+    }
 }
 
 module.exports = WebWorker;