Работа над BookUpdateChecker
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
const JembaConnManager = require('../../db/JembaConnManager');//singleton
|
||||
|
||||
const ayncExit = new (require('../AsyncExit'))();
|
||||
const utils = require('../utils');
|
||||
const log = new (require('../AppLogger'))().log;//singleton
|
||||
|
||||
const minuteMs = 60*1000;
|
||||
const hourMs = 60*minuteMs;
|
||||
|
||||
let instance = null;
|
||||
|
||||
//singleton
|
||||
class BUCClient {
|
||||
constructor(config) {
|
||||
if (!instance) {
|
||||
this.config = config;
|
||||
|
||||
this.connManager = new JembaConnManager();
|
||||
this.db = this.connManager.db['book-update-server'];
|
||||
|
||||
//константы
|
||||
if (this.config.branch !== 'development') {
|
||||
this.syncPeriod = 1*hourMs;//период синхронизации с сервером BUC
|
||||
} else {
|
||||
this.syncPeriod = 1*minuteMs;//период синхронизации с сервером BUC
|
||||
}
|
||||
|
||||
this.fromCheckTime = 1;
|
||||
|
||||
this.main();//no await
|
||||
|
||||
instance = this;
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
async checkBuc(bookUrls) {
|
||||
return [];
|
||||
}
|
||||
|
||||
async findMaxCheckTime() {
|
||||
let result = 1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async main() {
|
||||
if (!this.config.bucEnabled)
|
||||
throw new Error('BookUpdateChecker disabled');
|
||||
|
||||
try {
|
||||
this.fromCheckTime = await this.findMaxCheckTime();
|
||||
this.periodicSync();//no await
|
||||
|
||||
log(`BUC Client started`);
|
||||
} catch (e) {
|
||||
log(LM_FATAL, e.stack);
|
||||
ayncExit.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BUCClient;
|
||||
@@ -17,7 +17,7 @@ let instance = null;
|
||||
class BUCServer {
|
||||
constructor(config) {
|
||||
if (!instance) {
|
||||
this.config = Object.assign({}, config);
|
||||
this.config = config;
|
||||
|
||||
//константы
|
||||
if (this.config.branch !== 'development') {
|
||||
@@ -52,6 +52,8 @@ class BUCServer {
|
||||
this.checkQueue = [];
|
||||
this.hostChecking = {};
|
||||
|
||||
this.main(); //no await
|
||||
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@@ -260,9 +262,9 @@ await this.db.insert({
|
||||
for (let i = 0; i < 10; i++)
|
||||
this.periodicCheck();//no await
|
||||
|
||||
log(`---------------------------`);
|
||||
log(`Book Update checker started`);
|
||||
log(`---------------------------`);
|
||||
log(`------------------`);
|
||||
log(`BUC Server started`);
|
||||
log(`------------------`);
|
||||
} catch (e) {
|
||||
log(LM_FATAL, e.stack);
|
||||
ayncExit.exit(1);
|
||||
@@ -270,4 +272,4 @@ await this.db.insert({
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BUCServer;
|
||||
module.exports = BUCServer;
|
||||
|
||||
Reference in New Issue
Block a user