fix(core): update
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import * as plugins from './taskbuffer.plugins.js';
|
||||
import { Task } from './taskbuffer.classes.task.js';
|
||||
import { DistributedCoordinator } from './taskbuffer.classes.distributedcoordinator.js';
|
||||
|
||||
export interface ICronJob {
|
||||
cronString: string;
|
||||
@@ -7,12 +8,20 @@ export interface ICronJob {
|
||||
job: any;
|
||||
}
|
||||
|
||||
export interface ITaskManagerConstructorOptions {
|
||||
distributedCoordinator?: DistributedCoordinator
|
||||
}
|
||||
|
||||
export class TaskManager {
|
||||
public taskMap = new plugins.lik.ObjectMap<Task>();
|
||||
private cronJobManager = new plugins.smarttime.CronManager();
|
||||
|
||||
constructor() {
|
||||
// nothing here
|
||||
public options: ITaskManagerConstructorOptions = {
|
||||
distributedCoordinator: null
|
||||
};
|
||||
|
||||
constructor(optionosArg: ITaskManagerConstructorOptions) {
|
||||
this.options = Object.assign(this.options, optionosArg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +77,7 @@ export class TaskManager {
|
||||
*/
|
||||
public scheduleTaskByName(taskNameArg: string, cronStringArg: string) {
|
||||
const taskToSchedule = this.getTaskByName(taskNameArg);
|
||||
const cronJob = this.cronJobManager.addCronjob(cronStringArg, async () => {
|
||||
const cronJob = this.cronJobManager.addCronjob(cronStringArg, async (triggerTimeArg: number) => {
|
||||
console.log(`taskbuffer schedule triggered task >>${taskToSchedule.name}<<`);
|
||||
console.log(
|
||||
`task >>${taskToSchedule.name}<< is ${
|
||||
@@ -77,6 +86,17 @@ export class TaskManager {
|
||||
: `unbuffered`
|
||||
}`
|
||||
);
|
||||
if (this.options.distributedCoordinator) {
|
||||
console.log(`Found a distrubuted coordinator, performing distributed consultation.`);
|
||||
const announcementResult = this.options.distributedCoordinator.announceDistributedDecisionInfoBasis({
|
||||
status: 'requesting',
|
||||
taskExecutionParallel: 1,
|
||||
taskExecutionTime: triggerTimeArg,
|
||||
taskExecutionTimeout: taskToSchedule.timeout,
|
||||
taskName: taskToSchedule.name,
|
||||
taskVersion: taskToSchedule.version,
|
||||
})
|
||||
}
|
||||
await taskToSchedule.trigger();
|
||||
});
|
||||
taskToSchedule.cronJob = cronJob;
|
||||
|
Reference in New Issue
Block a user