fix(core): update
This commit is contained in:
parent
be3d2d41d6
commit
6373a74fb3
@ -1,12 +1,16 @@
|
|||||||
import * as plugins from './taskbuffer.plugins';
|
import * as plugins from './taskbuffer.plugins';
|
||||||
import { Task } from './taskbuffer.classes.task';
|
import { Task } from './taskbuffer.classes.task';
|
||||||
|
|
||||||
// interfaces
|
export interface ICronJob {
|
||||||
import { Objectmap } from '@pushrocks/lik';
|
cronString: string;
|
||||||
|
taskNameArg: string;
|
||||||
|
job: any;
|
||||||
|
}
|
||||||
|
|
||||||
export class TaskManager {
|
export class TaskManager {
|
||||||
public taskMap = new plugins.lik.Objectmap<Task>();
|
public taskMap = new plugins.lik.Objectmap<Task>();
|
||||||
private cronJobMap = new plugins.lik.Objectmap<ICronJob>();
|
private cronJobMap = new plugins.lik.Objectmap<ICronJob>();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// nothing here
|
// nothing here
|
||||||
}
|
}
|
||||||
@ -55,6 +59,10 @@ export class TaskManager {
|
|||||||
return taskToTrigger.trigger();
|
return taskToTrigger.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async triggerTask(task: Task) {
|
||||||
|
return task.trigger();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* schedules the task by name
|
* schedules the task by name
|
||||||
* @param taskNameArg
|
* @param taskNameArg
|
||||||
@ -71,25 +79,31 @@ export class TaskManager {
|
|||||||
this.cronJobMap.add({
|
this.cronJobMap.add({
|
||||||
taskNameArg: taskToSchedule.name,
|
taskNameArg: taskToSchedule.name,
|
||||||
cronString: cronStringArg,
|
cronString: cronStringArg,
|
||||||
job: job
|
job
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deschedules a task by name
|
||||||
|
* @param taskNameArg
|
||||||
|
*/
|
||||||
public descheduleTaskByName(taskNameArg: string) {
|
public descheduleTaskByName(taskNameArg: string) {
|
||||||
const descheduledCron = this.cronJobMap.findOneAndRemove(itemArg => {
|
const descheduledCron = this.cronJobMap.findOneAndRemove(itemArg => {
|
||||||
return itemArg.taskNameArg === taskNameArg;
|
return itemArg.taskNameArg === taskNameArg;
|
||||||
});
|
});
|
||||||
descheduledCron.job.stop();
|
descheduledCron.job.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deschedules a task
|
||||||
|
* @param task
|
||||||
|
*/
|
||||||
|
public async descheduleTask(task: Task) {
|
||||||
|
await this.descheduleTaskByName(task.name);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* returns all schedules of a specific task
|
* returns all schedules of a specific task
|
||||||
* @param taskNameArg
|
* @param taskNameArg
|
||||||
*/
|
*/
|
||||||
public getSchedulesForTaskName(taskNameArg: string) {}
|
public getSchedulesForTaskName(taskNameArg: string) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICronJob {
|
|
||||||
cronString: string;
|
|
||||||
taskNameArg: string;
|
|
||||||
job: any;
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
let cron = require('cron');
|
import cron from 'cron';
|
||||||
import * as lik from '@pushrocks/lik';
|
import * as lik from '@pushrocks/lik';
|
||||||
import * as rxjs from 'rxjs';
|
import * as rxjs from 'rxjs';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
Loading…
Reference in New Issue
Block a user