UNPKG

@golemio/energetics

Version:
66 lines 3.81 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); const UnimonitorCemApiHelper_1 = require("../../shared/helpers/UnimonitorCemApiHelper"); const FetchXHoursDataValidationSchema_1 = require("../schema/FetchXHoursDataValidationSchema"); const _sch_1 = require("../../../schema-definitions"); const helpers_1 = require("@golemio/core/dist/helpers"); const CoreToken_1 = require("@golemio/core/dist/helpers/ioc/CoreToken"); const AbstractTask_1 = require("@golemio/core/dist/integration-engine/workers/AbstractTask"); const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors"); const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe"); const ModuleContainer_1 = require("../ioc/ModuleContainer"); const FetchDateFactory_1 = require("./FetchDateFactory"); let FetchXHoursDataTask = class FetchXHoursDataTask extends AbstractTask_1.AbstractTask { constructor(config, fetchDataFactory) { super(_sch_1.EnergeticsSchema.name.toLowerCase()); this.config = config; this.fetchDataFactory = fetchDataFactory; this.queueName = "fetchVpalacXHoursData"; this.schema = FetchXHoursDataValidationSchema_1.FetchXHoursDataValidationSchema; this.queueTtl = 60 * 60 * 1000; //> 1 hour const { url, config: cemConfig } = this.getProviderConfig(); this.unimonitorCemApi = new UnimonitorCemApiHelper_1.UnimonitorCemApiHelper(url, cemConfig); } async execute(msg) { const authCookie = await this.unimonitorCemApi.createSession(); try { const targetHours = msg.targetHours; const now = (0, helpers_1.dateTime)(new Date()).setTimeZone(UnimonitorCemApiHelper_1.UnimonitorCemApiHelper.API_DATE_TZ); const timeFrom = now.clone().subtract(targetHours, "hours").valueOf().toString(); const timeTo = now.valueOf().toString(); await this.fetchDataFactory.fetchAndSaveData(timeFrom, timeTo, authCookie); } catch (err) { throw new golemio_errors_1.GeneralError(`Error while executing FetchXHoursDataTask.`, this.constructor.name, err); } finally { await this.unimonitorCemApi.terminateSession(authCookie); } } getProviderConfig() { return { url: this.config.getValue("module.UnimonitorCemApiEnergetics.url"), config: this.config.getValue("module.UnimonitorCemApiEnergetics"), }; } }; FetchXHoursDataTask = __decorate([ (0, tsyringe_1.injectable)(), __param(0, (0, tsyringe_1.inject)(CoreToken_1.CoreToken.SimpleConfig)), __param(1, (0, tsyringe_1.inject)(ModuleContainer_1.VpalaceContainerToken.FetchDateFactory)), __metadata("design:paramtypes", [Object, FetchDateFactory_1.FetchDateFactory]) ], FetchXHoursDataTask); exports.default = FetchXHoursDataTask; //# sourceMappingURL=FetchXHoursDataTask.js.map