ReaderWorker теперь синглтон
This commit is contained in:
@@ -8,10 +8,12 @@ const BookConverter = require('./BookConverter');
|
|||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const log = new (require('./AppLogger'))().log;//singleton
|
const log = new (require('./AppLogger'))().log;//singleton
|
||||||
|
|
||||||
let singleCleanExecute = false;
|
let instance = null;
|
||||||
|
|
||||||
|
//singleton
|
||||||
class ReaderWorker {
|
class ReaderWorker {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
|
if (!instance) {
|
||||||
this.config = Object.assign({}, config);
|
this.config = Object.assign({}, config);
|
||||||
|
|
||||||
this.config.tempDownloadDir = `${config.tempDir}/download`;
|
this.config.tempDownloadDir = `${config.tempDir}/download`;
|
||||||
@@ -25,11 +27,13 @@ class ReaderWorker {
|
|||||||
this.decomp = new FileDecompressor();
|
this.decomp = new FileDecompressor();
|
||||||
this.bookConverter = new BookConverter(this.config);
|
this.bookConverter = new BookConverter(this.config);
|
||||||
|
|
||||||
if (!singleCleanExecute) {
|
|
||||||
this.periodicCleanDir(this.config.tempPublicDir, this.config.maxTempPublicDirSize, 60*60*1000);//1 раз в час
|
this.periodicCleanDir(this.config.tempPublicDir, this.config.maxTempPublicDirSize, 60*60*1000);//1 раз в час
|
||||||
this.periodicCleanDir(this.config.uploadDir, this.config.maxUploadPublicDirSize, 60*60*1000);//1 раз в час
|
this.periodicCleanDir(this.config.uploadDir, this.config.maxUploadPublicDirSize, 60*60*1000);//1 раз в час
|
||||||
singleCleanExecute = true;
|
|
||||||
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadBook(opts, wState) {
|
async loadBook(opts, wState) {
|
||||||
|
|||||||
Reference in New Issue
Block a user