@golemio/parkings
Version:
Golemio Parkings Module
61 lines • 3.77 kB
JavaScript
;
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 });
exports.GenerateSmart4CityTaskListTask = exports.Smart4CityTaskType = void 0;
const SmartCityListDatasourceCache_1 = require("../../datasources/smart4city/SmartCityListDatasourceCache");
const Smart4CityTaskTypeSchema_1 = require("../schemas/Smart4CityTaskTypeSchema");
const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
const integration_engine_1 = require("@golemio/core/dist/integration-engine");
const constants_1 = require("../constants");
const ModuleContainerToken_1 = require("../../ioc/ModuleContainerToken");
const CoreToken_1 = require("@golemio/core/dist/helpers/ioc/CoreToken");
const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
var Smart4CityTaskType;
(function (Smart4CityTaskType) {
Smart4CityTaskType["locations"] = "locations";
Smart4CityTaskType["measurements"] = "measurements";
})(Smart4CityTaskType || (exports.Smart4CityTaskType = Smart4CityTaskType = {}));
let GenerateSmart4CityTaskListTask = exports.GenerateSmart4CityTaskListTask = class GenerateSmart4CityTaskListTask extends integration_engine_1.AbstractTask {
constructor(config, dataSource) {
super(constants_1.NEW_PARKINGS_WORKER_NAME);
this.config = config;
this.dataSource = dataSource;
this.queueName = "generateSmart4CityTaskList";
this.queueTtl = 3 * 60 * 60 * 1000; // 3h
this.schema = Smart4CityTaskTypeSchema_1.Smart4CityTaskTypeValidationSchema;
}
async execute(data) {
let sourceDataCityList = [];
try {
sourceDataCityList = await this.dataSource.getAll();
}
catch (err) {
if (err instanceof golemio_errors_1.AbstractGolemioError) {
throw err;
}
throw new golemio_errors_1.DatasourceError("Error while fetching Smart4City list", this.constructor.name, err);
}
const exchange = this.config.getValue("env.RABBIT_EXCHANGE_NAME");
for (const city of sourceDataCityList) {
await integration_engine_1.QueueManager.sendMessageToExchange(exchange + "." + constants_1.NEW_PARKINGS_WORKER_NAME.toLowerCase(), data.type === Smart4CityTaskType.locations ? "updateSmart4CityLocations" : "updateSmart4CityMeasurements", { code: city.code });
}
}
};
exports.GenerateSmart4CityTaskListTask = GenerateSmart4CityTaskListTask = __decorate([
(0, tsyringe_1.injectable)(),
__param(0, (0, tsyringe_1.inject)(CoreToken_1.CoreToken.SimpleConfig)),
__param(1, (0, tsyringe_1.inject)(ModuleContainerToken_1.ModuleContainerToken.SmartCityListDatasourceCache)),
__metadata("design:paramtypes", [Object, SmartCityListDatasourceCache_1.SmartCityListDatasourceCache])
], GenerateSmart4CityTaskListTask);
//# sourceMappingURL=GenerateSmart4CityTaskListTask.js.map