smarttime/ts/smarttime.classes.cronmanager.ts
2019-04-10 14:06:20 +02:00

36 lines
774 B
TypeScript

import * as plugins from './smarttime.plugins';
export class CronManager {
public status: 'started' | 'stopped' = 'stopped';
public cronjobs: plugins.cron.CronJob[] = [];
public addCronjob(cronIdentifierArg: string, cronFunctionArg: plugins.cron.CronCommand) {
const newCronJob = new plugins.cron.CronJob(cronIdentifierArg,cronFunctionArg);
if (this.status === 'started') {
newCronJob.start();
}
this.cronjobs.push(newCronJob);
};
/**
* starts the cronjob
*/
public start() {
this.status = 'started';
for (const cron of this.cronjobs) {
cron.start();
}
}
/**
* stops all cronjobs
*/
public stop() {
this.status = 'stopped';
for (const cron of this.cronjobs) {
cron.stop();
}
}
}