BUCClient.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const JembaConnManager = require('../../db/JembaConnManager');//singleton
  2. const ayncExit = new (require('../AsyncExit'))();
  3. const utils = require('../utils');
  4. const log = new (require('../AppLogger'))().log;//singleton
  5. const minuteMs = 60*1000;
  6. const hourMs = 60*minuteMs;
  7. let instance = null;
  8. //singleton
  9. class BUCClient {
  10. constructor(config) {
  11. if (!instance) {
  12. this.config = config;
  13. this.connManager = new JembaConnManager();
  14. this.db = this.connManager.db['book-update-server'];
  15. //константы
  16. if (this.config.branch !== 'development') {
  17. this.syncPeriod = 1*hourMs;//период синхронизации с сервером BUC
  18. } else {
  19. this.syncPeriod = 1*minuteMs;//период синхронизации с сервером BUC
  20. }
  21. this.fromCheckTime = 1;
  22. this.main();//no await
  23. instance = this;
  24. }
  25. return instance;
  26. }
  27. async checkBuc(bookUrls) {
  28. return [];
  29. }
  30. async findMaxCheckTime() {
  31. let result = 1;
  32. return result;
  33. }
  34. async main() {
  35. if (!this.config.bucEnabled)
  36. throw new Error('BookUpdateChecker disabled');
  37. try {
  38. this.fromCheckTime = await this.findMaxCheckTime();
  39. this.periodicSync();//no await
  40. log(`BUC Client started`);
  41. } catch (e) {
  42. log(LM_FATAL, e.stack);
  43. ayncExit.exit(1);
  44. }
  45. }
  46. }
  47. module.exports = BUCClient;