Cron implemented

This commit is contained in:
Wolfgang Hottgenroth
2018-01-15 17:49:25 +01:00
parent 09a63fe736
commit 9c0ac6dc3b
9 changed files with 107 additions and 2 deletions

23
dist/Cron.js vendored Normal file
View File

@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const logger = require("./log");
const MqttDispatcher_1 = require("./MqttDispatcher");
const cron = require("cron");
class Cron {
constructor(name, target, crontab) {
this.name = name;
this.targetTopic = target.getInTopic();
this.crontab = crontab;
}
start() {
this.crontab.forEach((cronEntry) => {
logger.info(`Starting cronjob for: ${this.targetTopic}, ${cronEntry.output} at ${cronEntry.cronTime}`);
cronEntry.cronJob = new cron.CronJob(cronEntry.cronTime, () => {
logger.info(`Firing ${this.targetTopic}, ${cronEntry.output}`);
MqttDispatcher_1.mqttHandler.send(this.targetTopic, cronEntry.output);
}, undefined, true, 'Europe/Berlin');
});
}
}
exports.Cron = Cron;
//# sourceMappingURL=Cron.js.map