"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const plugins = require("./taskbuffer.plugins"); class TaskManager { constructor() { this.taskMap = new plugins.lik.Objectmap(); this.cronJobArray = []; // nothing here } /** * checks if a task is already present * @param taskNameArg */ getTaskByName(taskNameArg) { return this.taskMap.find((itemArg) => { return itemArg.name === taskNameArg; }); } /** * adds a Task to the TaskManager * @param taskArg */ addTask(taskArg) { if (!taskArg.name) { throw new Error('taskArg needs a name to be added to taskManager'); } this.taskMap.add(taskArg); } /** * adds and schedules a task at once * @param taskArg * @param cronStringArg */ addAndScheduleTask(taskArg, cronStringArg) { this.addTask(taskArg); let taskName = taskArg.name; this.scheduleTaskByName(taskName, cronStringArg); } /** * triggers a task in the TaskManagerByName * @param taskNameArg */ triggerTaskByName(taskNameArg) { let taskToTrigger = this.getTaskByName(taskNameArg); if (!taskToTrigger) { throw new Error(`There is no task with the name of ${taskNameArg}`); } taskToTrigger.trigger(); } /** * schedules the task by name * @param taskNameArg */ scheduleTaskByName(taskNameArg, cronStringArg) { let taskToSchedule = this.getTaskByName(taskNameArg); let job = new plugins.cron.CronJob({ cronTime: cronStringArg, onTick: taskToSchedule.trigger, start: true }); this.cronJobArray.push({ taskNameArg: taskToSchedule.name, cronString: cronStringArg, job: job }); } /** * returns all schedules of a specific task * @param taskNameArg */ getSchedulesForTaskName(taskNameArg) { } } exports.TaskManager = TaskManager; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFza2J1ZmZlci5jbGFzc2VzLnRhc2ttYW5hZ2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvdGFza2J1ZmZlci5jbGFzc2VzLnRhc2ttYW5hZ2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsZ0RBQStDO0FBTS9DO0lBR0U7UUFGQSxZQUFPLEdBQUcsSUFBSSxPQUFPLENBQUMsR0FBRyxDQUFDLFNBQVMsRUFBUS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