UNPKG

youzanyun-devtool-worker

Version:

54 lines (53 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const spring4js_nodejs_1 = require("spring4js-nodejs"); const TIME = 4000; let DatabasePollService = class DatabasePollService { constructor() { this._DBPoll = new spring4js_nodejs_1.Emitter(); this.onDBPoll = this._DBPoll.registerEvent; this._pollError = new spring4js_nodejs_1.Emitter(); this.onPollError = this._pollError.registerEvent; } async start() { } async loop() { if (!this.isPolling) { return; } try { const downloadStatus = await this.databaseService.getDouckerStatus(['-t', this.dbType, '-i']); const startStatus = await this.databaseService.getDouckerStatus(['-t', this.dbType, '-p']); this._DBPoll.fire({ type: `${this.dbType}Status`, data: { downloadStatus, startStatus } }); setTimeout(this.loop.bind(this), TIME); } catch (error) { console.log(error); this._pollError.fire({ type: "statusError", message: error, data: error, code: 500 }); } } startLoop(type, projectId) { this.isPolling = true; this.projectId = projectId; this.dbType = type; this.loop(); } stopLoop() { this.isPolling = false; } }; tslib_1.__decorate([ (0, spring4js_nodejs_1.Resource)() ], DatabasePollService.prototype, "databaseService", void 0); DatabasePollService = tslib_1.__decorate([ (0, spring4js_nodejs_1.Service)() ], DatabasePollService); exports.default = DatabasePollService;