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

для автоматического пересоздания поисковой БД
This commit is contained in:
Book Pauk
2022-10-02 15:54:40 +07:00
parent 0946941e59
commit fe0f272acc
3 changed files with 33 additions and 0 deletions

View File

@@ -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'],

View File

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

View File

@@ -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;