feat(taskrunner): now has working taskrunner
This commit is contained in:
parent
af5fa857cc
commit
138aefc499
@ -4,7 +4,7 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
@ -20,17 +20,19 @@ mirror:
|
|||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
snyk:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@ -47,6 +49,7 @@ testStable:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
@ -54,22 +57,24 @@ testBuild:
|
|||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@ -81,9 +86,11 @@ codequality:
|
|||||||
allow_failure: true
|
allow_failure: true
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
@ -94,20 +101,20 @@ trigger:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-dbase:npmci
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
|
- npmci node install lts
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
|
12
package.json
12
package.json
@ -44,12 +44,12 @@
|
|||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/*",
|
"ts/**/*",
|
||||||
"ts_web/*",
|
"ts_web/**/*",
|
||||||
"dist/*",
|
"dist/**/*",
|
||||||
"dist_web/*",
|
"dist_web/**/*",
|
||||||
"dist_ts_web/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
@ -44,6 +44,11 @@ For further information read the linked docs at the top of this README.
|
|||||||
|
|
||||||
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)
|
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)
|
||||||
|
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
@ -17,7 +17,7 @@ tap.test('should create tasks', async () => {
|
|||||||
});
|
});
|
||||||
afterTask = new taskbuffer.Task({
|
afterTask = new taskbuffer.Task({
|
||||||
name: 'myAfterTask',
|
name: 'myAfterTask',
|
||||||
taskFunction: async (x) => {
|
taskFunction: async x => {
|
||||||
if (x === 'hi') {
|
if (x === 'hi') {
|
||||||
console.log('afterTask: values get passed along alright');
|
console.log('afterTask: values get passed along alright');
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ tap.test('should create tasks', async () => {
|
|||||||
|
|
||||||
mainTask = new taskbuffer.Task({
|
mainTask = new taskbuffer.Task({
|
||||||
name: 'mainTask',
|
name: 'mainTask',
|
||||||
taskFunction: async (x) => {
|
taskFunction: async x => {
|
||||||
if (x === 'hi') {
|
if (x === 'hi') {
|
||||||
console.log('mainTask: values get passed along alright');
|
console.log('mainTask: values get passed along alright');
|
||||||
}
|
}
|
||||||
|
29
test/test.taskrunner.ts
Normal file
29
test/test.taskrunner.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
|
import * as taskbuffer from '../ts/index';
|
||||||
|
|
||||||
|
let testTaskRunner: taskbuffer.TaskRunner;
|
||||||
|
|
||||||
|
tap.test('should create a valid taskrunner', async () => {
|
||||||
|
testTaskRunner = new taskbuffer.TaskRunner();
|
||||||
|
testTaskRunner.start();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should execute task when its scheduled', async (tools) => {
|
||||||
|
const done = tools.defer();
|
||||||
|
testTaskRunner.addTask(new taskbuffer.Task({
|
||||||
|
taskFunction: async () => {
|
||||||
|
console.log('hi');
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
testTaskRunner.addTask(new taskbuffer.Task({
|
||||||
|
taskFunction: async () => {
|
||||||
|
console.log('there');
|
||||||
|
done.resolve();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
await done.promise;
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -3,6 +3,4 @@ export { Taskchain } from './taskbuffer.classes.taskchain';
|
|||||||
export { Taskparallel } from './taskbuffer.classes.taskparallel';
|
export { Taskparallel } from './taskbuffer.classes.taskparallel';
|
||||||
export { TaskManager } from './taskbuffer.classes.taskmanager';
|
export { TaskManager } from './taskbuffer.classes.taskmanager';
|
||||||
export { TaskOnce } from './taskbuffer.classes.taskonce';
|
export { TaskOnce } from './taskbuffer.classes.taskonce';
|
||||||
|
export { TaskRunner } from './taskbuffer.classes.taskrunner';
|
||||||
// import for naming only
|
|
||||||
import './taskbuffer.classes.helpers';
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Task } from "./taskbuffer.classes.task";
|
import { Task } from './taskbuffer.classes.task';
|
||||||
|
|
||||||
export class BufferRunner {
|
export class BufferRunner {
|
||||||
public task: Task;
|
public task: Task;
|
||||||
|
@ -1,5 +1,2 @@
|
|||||||
import plugins = require('./taskbuffer.plugins');
|
import plugins = require('./taskbuffer.plugins');
|
||||||
import { Task, ITaskFunction } from './taskbuffer.classes.task';
|
import { Task, ITaskFunction } from './taskbuffer.classes.task';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,11 +13,11 @@ export class Task {
|
|||||||
// STATIC
|
// STATIC
|
||||||
public static extractTask(preOrAfterTaskArg: Task | TPreOrAfterTaskFunction): Task {
|
public static extractTask(preOrAfterTaskArg: Task | TPreOrAfterTaskFunction): Task {
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case (!preOrAfterTaskArg):
|
case !preOrAfterTaskArg:
|
||||||
return null;
|
return null;
|
||||||
case (preOrAfterTaskArg instanceof Task):
|
case preOrAfterTaskArg instanceof Task:
|
||||||
return preOrAfterTaskArg as Task;
|
return preOrAfterTaskArg as Task;
|
||||||
case typeof preOrAfterTaskArg === "function":
|
case typeof preOrAfterTaskArg === 'function':
|
||||||
const taskFunction = preOrAfterTaskArg as TPreOrAfterTaskFunction;
|
const taskFunction = preOrAfterTaskArg as TPreOrAfterTaskFunction;
|
||||||
return taskFunction();
|
return taskFunction();
|
||||||
default:
|
default:
|
||||||
@ -25,7 +25,6 @@ export class Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static emptyTaskFunction: ITaskFunction = function(x) {
|
public static emptyTaskFunction: ITaskFunction = function(x) {
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
done.resolve();
|
done.resolve();
|
||||||
@ -40,7 +39,10 @@ export class Task {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static isTaskTouched = (taskArg: Task | TPreOrAfterTaskFunction, touchedTasksArray: Task[]): boolean => {
|
public static isTaskTouched = (
|
||||||
|
taskArg: Task | TPreOrAfterTaskFunction,
|
||||||
|
touchedTasksArray: Task[]
|
||||||
|
): boolean => {
|
||||||
const taskToCheck = Task.extractTask(taskArg);
|
const taskToCheck = Task.extractTask(taskArg);
|
||||||
let result = false;
|
let result = false;
|
||||||
for (const keyArg in touchedTasksArray) {
|
for (const keyArg in touchedTasksArray) {
|
||||||
@ -51,7 +53,10 @@ export class Task {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
public static runTask = async (taskArg: Task | TPreOrAfterTaskFunction, optionsArg: { x?; touchedTasksArray?: Task[] }) => {
|
public static runTask = async (
|
||||||
|
taskArg: Task | TPreOrAfterTaskFunction,
|
||||||
|
optionsArg: { x?; touchedTasksArray?: Task[] }
|
||||||
|
) => {
|
||||||
const taskToRun = Task.extractTask(taskArg);
|
const taskToRun = Task.extractTask(taskArg);
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
|
|
||||||
@ -116,7 +121,7 @@ export class Task {
|
|||||||
});
|
});
|
||||||
localDeferred.resolve();
|
localDeferred.resolve();
|
||||||
return await done.promise;
|
return await done.promise;
|
||||||
}
|
};
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
// man datory properties
|
// man datory properties
|
||||||
|
@ -8,11 +8,18 @@ export class TaskRunner {
|
|||||||
public runningTasks: plugins.lik.Objectmap<Task> = new plugins.lik.Objectmap<Task>();
|
public runningTasks: plugins.lik.Objectmap<Task> = new plugins.lik.Objectmap<Task>();
|
||||||
public qeuedTasks: Task[] = [];
|
public qeuedTasks: Task[] = [];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.runningTasks.eventSubject.subscribe(async eventArg => {
|
||||||
|
this.checkExecution();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* adds a task to the qeue
|
* adds a task to the qeue
|
||||||
*/
|
*/
|
||||||
public addTask(taskArg: Task) {
|
public addTask(taskArg: Task) {
|
||||||
this.qeuedTasks.push(taskArg);
|
this.qeuedTasks.push(taskArg);
|
||||||
|
this.checkExecution();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,12 +37,20 @@ export class TaskRunner {
|
|||||||
this.status = 'running';
|
this.status = 'running';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks wether execution is on point
|
||||||
|
*/
|
||||||
public async checkExecution() {
|
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();
|
const nextJob = this.qeuedTasks.shift();
|
||||||
this.runningTasks.add(nextJob);
|
this.runningTasks.add(nextJob);
|
||||||
await nextJob.trigger();
|
await nextJob.trigger();
|
||||||
|
this.runningTasks.remove(nextJob);
|
||||||
|
this.checkExecution();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,5 +59,5 @@ export class TaskRunner {
|
|||||||
*/
|
*/
|
||||||
public stop() {
|
public stop() {
|
||||||
this.status = 'stopped';
|
this.status = 'stopped';
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user