2019-04-10 09:34:30 +00:00
|
|
|
import * as plugins from './smarttime.plugins';
|
|
|
|
|
2019-04-10 12:06:20 +00:00
|
|
|
export class CronManager {
|
|
|
|
public status: 'started' | 'stopped' = 'stopped';
|
|
|
|
|
|
|
|
public cronjobs: plugins.cron.CronJob[] = [];
|
|
|
|
|
|
|
|
public addCronjob(cronIdentifierArg: string, cronFunctionArg: plugins.cron.CronCommand) {
|
2019-06-17 14:54:39 +00:00
|
|
|
const newCronJob = new plugins.cron.CronJob(cronIdentifierArg, cronFunctionArg);
|
2019-04-10 12:06:20 +00:00
|
|
|
if (this.status === 'started') {
|
|
|
|
newCronJob.start();
|
|
|
|
}
|
|
|
|
this.cronjobs.push(newCronJob);
|
2019-06-17 14:54:39 +00:00
|
|
|
}
|
2019-04-10 12:06:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|