feat(taskrunner): now has working taskrunner
This commit is contained in:
@@ -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';
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user