@kaguya-anime/parsers
Advanced tools
Comparing version 1.12.1 to 1.13.0
@@ -0,1 +1,2 @@ | ||
import Scraper from './Scraper'; | ||
export declare const DEFAULT_MONITOR_INTERVAL = 1200000; | ||
@@ -9,6 +10,9 @@ export default class Monitor { | ||
oldData: any; | ||
static queueList: Scraper[]; | ||
constructor(onRequest: () => Promise<any>, shouldChange: (oldData?: any, newData?: any) => Promise<boolean>); | ||
onMonitorChange(): void; | ||
run(): void; | ||
onMonitorChange(): Promise<void>; | ||
run(onRun: () => any): void; | ||
check(): Promise<void>; | ||
static addToQueue(parser: Scraper): void; | ||
static runNextParser(): Promise<void>; | ||
} |
@@ -14,25 +14,49 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
onMonitorChange() { | ||
console.log('Method not implemented.'); | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
console.log('Method not implemented.'); | ||
}); | ||
} | ||
run() { | ||
run(onRun) { | ||
if (this.isDisabled) | ||
return; | ||
setInterval(this.check.bind(this), this.interval); | ||
setInterval(onRun, this.interval); | ||
} | ||
check() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (this.isRequestDisabled) { | ||
this.onMonitorChange(); | ||
return; | ||
try { | ||
if (this.isRequestDisabled) { | ||
yield this.onMonitorChange(); | ||
return; | ||
} | ||
const data = yield this.onRequest(); | ||
const shouldChange = yield this.shouldChange(this.oldData, data); | ||
if (shouldChange) { | ||
yield this.onMonitorChange(); | ||
} | ||
this.oldData = data; | ||
} | ||
const data = yield this.onRequest(); | ||
const shouldChange = yield this.shouldChange(this.oldData, data); | ||
if (shouldChange) { | ||
this.onMonitorChange(); | ||
catch (err) { | ||
console.log('Monitor error'); | ||
} | ||
this.oldData = data; | ||
}); | ||
} | ||
static addToQueue(parser) { | ||
this.queueList.push(parser); | ||
if (this.queueList.length === 1) { | ||
this.runNextParser(); | ||
} | ||
} | ||
static runNextParser() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const parser = this.queueList[0]; | ||
yield parser.monitor.check(); | ||
this.queueList.shift(); | ||
if (this.queueList.length > 0) { | ||
this.runNextParser(); | ||
} | ||
}); | ||
} | ||
} | ||
exports.default = Monitor; | ||
Monitor.queueList = []; | ||
//# sourceMappingURL=Monitor.js.map |
{ | ||
"name": "@kaguya-anime/parsers", | ||
"version": "1.12.1", | ||
"version": "1.13.0", | ||
"main": "build/index.js", | ||
@@ -43,3 +43,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "c7569a4f31c5f5637d7e173ce30d10b16f58185b" | ||
"gitHead": "4c36edcd73268f0e0493f6f3c1893818e860b455" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
428815
7705