feat(taskrunner): now has working taskrunner

This commit is contained in:
2019-11-28 11:33:26 +00:00
parent af5fa857cc
commit 138aefc499
11 changed files with 137 additions and 81 deletions

View File

@@ -8,11 +8,18 @@ export class TaskRunner {
public runningTasks: plugins.lik.Objectmap<Task> = new plugins.lik.Objectmap<Task>();
public qeuedTasks: Task[] = [];
constructor() {
this.runningTasks.eventSubject.subscribe(async eventArg => {
this.checkExecution();
});
}
/**
* adds a task to the qeue
*/
public addTask(taskArg: Task) {
this.qeuedTasks.push(taskArg);
this.checkExecution();
}
/**
@@ -30,12 +37,20 @@ export class TaskRunner {
this.status = 'running';
}
/**
* checks wether execution is on point
*/
public async checkExecution() {
if (this.runningTasks.getArray().length < this.maxParrallelJobs) {
if (
this.runningTasks.getArray().length < this.maxParrallelJobs &&
this.status === 'running' &&
this.qeuedTasks.length > 0
) {
const nextJob = this.qeuedTasks.shift();
this.runningTasks.add(nextJob);
await nextJob.trigger();
this.runningTasks.remove(nextJob);
this.checkExecution();
}
}
@@ -44,5 +59,5 @@ export class TaskRunner {
*/
public stop() {
this.status = 'stopped';
};
}
}