fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-05 11:35:26 +02:00
parent 4c7a373d98
commit eff9c6e6c9
7 changed files with 507 additions and 424 deletions

View File

@ -1,4 +1,4 @@
# gitzone standard # gitzone ci_default
image: hosttoday/ht-docker-node:npmci image: hosttoday/ht-docker-node:npmci
cache: cache:

843
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -27,20 +27,20 @@
}, },
"homepage": "https://gitlab.com/pushrocks/taskbuffer#readme", "homepage": "https://gitlab.com/pushrocks/taskbuffer#readme",
"dependencies": { "dependencies": {
"@pushrocks/lik": "^3.0.4", "@pushrocks/lik": "^3.0.11",
"@pushrocks/smartdelay": "^2.0.2", "@pushrocks/smartdelay": "^2.0.3",
"@pushrocks/smartlog": "^2.0.9", "@pushrocks/smartlog": "^2.0.19",
"@pushrocks/smartpromise": "^2.0.5", "@pushrocks/smartpromise": "^3.0.2",
"@types/cron": "^1.3.0", "@types/cron": "^1.7.1",
"cron": "^1.6.0", "cron": "^1.7.1",
"rxjs": "^6.3.3" "rxjs": "^6.5.3"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.4", "@gitzone/tsbuild": "^2.1.17",
"@gitzone/tstest": "^1.0.18", "@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^10.12.18", "@types/node": "^12.7.4",
"tslint": "^5.12.1", "tslint": "^5.19.0",
"tslint-config-prettier": "^1.17.0" "tslint-config-prettier": "^1.18.0"
} }
} }

View File

@ -1,11 +1,9 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import taskbuffer = require('../ts/index'); import taskbuffer = require('../ts/index');
import * as smartq from 'smartq';
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@pushrocks/smartdelay';
let task1Executed = false; let task1Executed = false;
let task1 = new taskbuffer.Task({ const task1 = new taskbuffer.Task({
taskFunction: async () => { taskFunction: async () => {
await smartdelay.delayFor(2000); await smartdelay.delayFor(2000);
task1Executed = true; task1Executed = true;
@ -13,7 +11,7 @@ let task1 = new taskbuffer.Task({
}); });
let task2Executed = false; let task2Executed = false;
let task2 = new taskbuffer.Task({ const task2 = new taskbuffer.Task({
taskFunction: async () => { taskFunction: async () => {
await smartdelay.delayFor(2000); await smartdelay.delayFor(2000);
task2Executed = true; task2Executed = true;
@ -21,7 +19,7 @@ let task2 = new taskbuffer.Task({
}); });
let task3Executed = false; let task3Executed = false;
let task3 = new taskbuffer.Task({ const task3 = new taskbuffer.Task({
taskFunction: async () => { taskFunction: async () => {
await smartdelay.delayFor(2000); await smartdelay.delayFor(2000);
task3Executed = true; task3Executed = true;
@ -29,7 +27,7 @@ let task3 = new taskbuffer.Task({
}); });
tap.test('expect run in Parallel', async () => { tap.test('expect run in Parallel', async () => {
let testTaskparallel = new taskbuffer.Taskparallel({ const testTaskparallel = new taskbuffer.Taskparallel({
taskArray: [task1, task2, task3] taskArray: [task1, task2, task3]
}); });
await testTaskparallel.trigger(); await testTaskparallel.trigger();

View File

@ -6,7 +6,7 @@ import * as smartdelay from '@pushrocks/smartdelay';
let myTaskManager: taskbuffer.TaskManager; let myTaskManager: taskbuffer.TaskManager;
let taskRunCounter = 0; let taskRunCounter = 0;
let taskDone = smartpromise.defer(); const taskDone = smartpromise.defer();
tap.test('should create an instance of TaskManager', async () => { tap.test('should create an instance of TaskManager', async () => {
myTaskManager = new taskbuffer.TaskManager(); myTaskManager = new taskbuffer.TaskManager();

View File

@ -4,9 +4,9 @@ import taskbuffer = require('../ts/index');
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay'; import * as smartdelay from '@pushrocks/smartdelay';
let flowTask1 = new taskbuffer.Task({ const flowTask1 = new taskbuffer.Task({
taskFunction: (x: number) => { taskFunction: (x: number) => {
let done = smartpromise.defer(); const done = smartpromise.defer();
console.log('flowTask1'); console.log('flowTask1');
console.log(x); console.log(x);
done.resolve(x); done.resolve(x);
@ -14,9 +14,9 @@ let flowTask1 = new taskbuffer.Task({
} }
}); });
let flowTaskBuffered = new taskbuffer.Task({ const flowTaskBuffered = new taskbuffer.Task({
taskFunction: (x: number) => { taskFunction: (x: number) => {
let done = smartpromise.defer(); const done = smartpromise.defer();
console.log('flowTask1'); console.log('flowTask1');
console.log(x); console.log(x);
done.resolve(x); done.resolve(x);
@ -26,9 +26,9 @@ let flowTaskBuffered = new taskbuffer.Task({
bufferMax: 1 bufferMax: 1
}); });
let flowTask2 = new taskbuffer.Task({ const flowTask2 = new taskbuffer.Task({
taskFunction: (x: number) => { taskFunction: (x: number) => {
let done = smartpromise.defer(); const done = smartpromise.defer();
console.log('flowTask2'); console.log('flowTask2');
console.log(x); console.log(x);
done.resolve(x); done.resolve(x);
@ -37,27 +37,27 @@ let flowTask2 = new taskbuffer.Task({
preTask: flowTask1 preTask: flowTask1
}); });
let flowTask3 = new taskbuffer.Taskchain({ const flowTask3 = new taskbuffer.Taskchain({
taskArray: [flowTask1, flowTask2] taskArray: [flowTask1, flowTask2]
}); });
tap.test('should let a value flow through a task', async () => { tap.test('should let a value flow through a task', async () => {
let result = await flowTask1.trigger(12); const result = await flowTask1.trigger(12);
expect(result).to.equal(12); expect(result).to.equal(12);
}); });
tap.test('expect values to flow between tasks', async () => { tap.test('expect values to flow between tasks', async () => {
let result = await flowTask2.trigger(12); const result = await flowTask2.trigger(12);
expect(result).to.equal(12); expect(result).to.equal(12);
}); });
tap.test('expect values to flow between tasks when buffered', async () => { tap.test('expect values to flow between tasks when buffered', async () => {
let result = await flowTaskBuffered.trigger(12); const result = await flowTaskBuffered.trigger(12);
expect(result).to.equal(12); expect(result).to.equal(12);
}); });
tap.test('expect values to flow between tasks in Taskchain', async () => { tap.test('expect values to flow between tasks in Taskchain', async () => {
let result = await flowTask3.trigger(12); const result = await flowTask3.trigger(12);
expect(result).to.equal(12); expect(result).to.equal(12);
}); });

View File

@ -5,7 +5,7 @@ import { Task } from './taskbuffer.classes.task';
import { Objectmap } from '@pushrocks/lik'; import { Objectmap } from '@pushrocks/lik';
export class TaskManager { export class TaskManager {
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
@ -15,7 +15,7 @@ export class TaskManager {
* checks if a task is already present * checks if a task is already present
* @param taskNameArg * @param taskNameArg
*/ */
getTaskByName(taskNameArg): Task { public getTaskByName(taskNameArg): Task {
return this.taskMap.find(itemArg => { return this.taskMap.find(itemArg => {
return itemArg.name === taskNameArg; return itemArg.name === taskNameArg;
}); });
@ -25,7 +25,7 @@ export class TaskManager {
* adds a Task to the TaskManager * adds a Task to the TaskManager
* @param taskArg * @param taskArg
*/ */
addTask(taskArg: Task): void { public addTask(taskArg: Task): void {
if (!taskArg.name) { if (!taskArg.name) {
throw new Error('taskArg needs a name to be added to taskManager'); throw new Error('taskArg needs a name to be added to taskManager');
} }
@ -37,9 +37,9 @@ export class TaskManager {
* @param taskArg * @param taskArg
* @param cronStringArg * @param cronStringArg
*/ */
addAndScheduleTask(taskArg: Task, cronStringArg: string) { public addAndScheduleTask(taskArg: Task, cronStringArg: string) {
this.addTask(taskArg); this.addTask(taskArg);
let taskName = taskArg.name; const taskName = taskArg.name;
this.scheduleTaskByName(taskName, cronStringArg); this.scheduleTaskByName(taskName, cronStringArg);
} }
@ -47,8 +47,8 @@ export class TaskManager {
* triggers a task in the TaskManagerByName * triggers a task in the TaskManagerByName
* @param taskNameArg * @param taskNameArg
*/ */
triggerTaskByName(taskNameArg: string): Promise<any> { public triggerTaskByName(taskNameArg: string): Promise<any> {
let taskToTrigger = this.getTaskByName(taskNameArg); const taskToTrigger = this.getTaskByName(taskNameArg);
if (!taskToTrigger) { if (!taskToTrigger) {
throw new Error(`There is no task with the name of ${taskNameArg}`); throw new Error(`There is no task with the name of ${taskNameArg}`);
} }
@ -59,9 +59,9 @@ export class TaskManager {
* schedules the task by name * schedules the task by name
* @param taskNameArg * @param taskNameArg
*/ */
scheduleTaskByName(taskNameArg: string, cronStringArg: string) { public scheduleTaskByName(taskNameArg: string, cronStringArg: string) {
let taskToSchedule = this.getTaskByName(taskNameArg); const taskToSchedule = this.getTaskByName(taskNameArg);
let job = new plugins.cron.CronJob({ const job = new plugins.cron.CronJob({
cronTime: cronStringArg, cronTime: cronStringArg,
onTick: () => { onTick: () => {
this.triggerTaskByName(taskNameArg); this.triggerTaskByName(taskNameArg);
@ -75,8 +75,8 @@ export class TaskManager {
}); });
} }
descheduleTaskByName(taskNameArg: string) { public descheduleTaskByName(taskNameArg: string) {
let 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();
@ -85,7 +85,7 @@ export class TaskManager {
* returns all schedules of a specific task * returns all schedules of a specific task
* @param taskNameArg * @param taskNameArg
*/ */
getSchedulesForTaskName(taskNameArg: string) {} public getSchedulesForTaskName(taskNameArg: string) {}
} }
export interface ICronJob { export interface ICronJob {