@push.rocks/taskbuffer 3.1.8 → 3.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_bundle/bundle.js +18 -8
- package/dist_bundle/bundle.js.map +2 -2
- package/dist_ts/00_commitinfo_data.js +2 -2
- package/dist_ts/taskbuffer.classes.bufferrunner.js +1 -1
- package/dist_ts/taskbuffer.classes.task.js +9 -4
- package/dist_ts/taskbuffer.classes.taskchain.js +1 -1
- package/dist_ts/taskbuffer.classes.taskdebounced.js +1 -1
- package/dist_ts/taskbuffer.classes.taskmanager.js +2 -2
- package/dist_ts/taskbuffer.classes.taskrunner.js +1 -1
- package/dist_ts/taskbuffer.plugins.d.ts +1 -1
- package/dist_ts/taskbuffer.plugins.js +2 -2
- package/npmextra.json +1 -1
- package/package.json +3 -3
- package/readme.md +407 -77
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/taskbuffer.classes.bufferrunner.ts +2 -3
- package/ts/taskbuffer.classes.distributedcoordinator.ts +2 -2
- package/ts/taskbuffer.classes.task.ts +15 -6
- package/ts/taskbuffer.classes.taskchain.ts +6 -2
- package/ts/taskbuffer.classes.taskdebounced.ts +3 -1
- package/ts/taskbuffer.classes.taskmanager.ts +13 -4
- package/ts/taskbuffer.classes.taskrunner.ts +2 -1
- package/ts/taskbuffer.plugins.ts +9 -1
|
@@ -13,9 +13,8 @@ export class BufferRunner {
|
|
|
13
13
|
if (!(this.bufferCounter >= this.task.bufferMax)) {
|
|
14
14
|
this.bufferCounter++;
|
|
15
15
|
}
|
|
16
|
-
const returnPromise: Promise<any> =
|
|
17
|
-
this.bufferCounter
|
|
18
|
-
);
|
|
16
|
+
const returnPromise: Promise<any> =
|
|
17
|
+
this.task.cycleCounter.getPromiseForCycle(this.bufferCounter);
|
|
19
18
|
if (!this.task.running) {
|
|
20
19
|
this._run(x);
|
|
21
20
|
}
|
|
@@ -26,11 +26,11 @@ export interface IDistributedTaskRequestResult {
|
|
|
26
26
|
|
|
27
27
|
export abstract class AbstractDistributedCoordinator {
|
|
28
28
|
public abstract fireDistributedTaskRequest(
|
|
29
|
-
infoBasis: IDistributedTaskRequest
|
|
29
|
+
infoBasis: IDistributedTaskRequest,
|
|
30
30
|
): Promise<IDistributedTaskRequestResult>;
|
|
31
31
|
|
|
32
32
|
public abstract updateDistributedTaskRequest(
|
|
33
|
-
infoBasis: IDistributedTaskRequest
|
|
33
|
+
infoBasis: IDistributedTaskRequest,
|
|
34
34
|
): Promise<void>;
|
|
35
35
|
|
|
36
36
|
public abstract start(): Promise<void>;
|
|
@@ -16,7 +16,7 @@ export type TPreOrAfterTaskFunction = () => Task<any>;
|
|
|
16
16
|
|
|
17
17
|
export class Task<T = undefined> {
|
|
18
18
|
public static extractTask<T = undefined>(
|
|
19
|
-
preOrAfterTaskArg: Task<T> | TPreOrAfterTaskFunction
|
|
19
|
+
preOrAfterTaskArg: Task<T> | TPreOrAfterTaskFunction,
|
|
20
20
|
): Task<T> {
|
|
21
21
|
switch (true) {
|
|
22
22
|
case !preOrAfterTaskArg:
|
|
@@ -47,7 +47,7 @@ export class Task<T = undefined> {
|
|
|
47
47
|
|
|
48
48
|
public static isTaskTouched<T = undefined>(
|
|
49
49
|
taskArg: Task<T> | TPreOrAfterTaskFunction,
|
|
50
|
-
touchedTasksArray: Task<T>[]
|
|
50
|
+
touchedTasksArray: Task<T>[],
|
|
51
51
|
): boolean {
|
|
52
52
|
const taskToCheck = Task.extractTask(taskArg);
|
|
53
53
|
let result = false;
|
|
@@ -61,7 +61,7 @@ export class Task<T = undefined> {
|
|
|
61
61
|
|
|
62
62
|
public static runTask = async <T>(
|
|
63
63
|
taskArg: Task<T> | TPreOrAfterTaskFunction,
|
|
64
|
-
optionsArg: { x?: any; touchedTasksArray?: Task<T>[] }
|
|
64
|
+
optionsArg: { x?: any; touchedTasksArray?: Task<T>[] },
|
|
65
65
|
) => {
|
|
66
66
|
const taskToRun = Task.extractTask(taskArg);
|
|
67
67
|
const done = plugins.smartpromise.defer();
|
|
@@ -105,7 +105,10 @@ export class Task<T = undefined> {
|
|
|
105
105
|
const localDeferred = plugins.smartpromise.defer();
|
|
106
106
|
localDeferred.promise
|
|
107
107
|
.then(() => {
|
|
108
|
-
if (
|
|
108
|
+
if (
|
|
109
|
+
taskToRun.preTask &&
|
|
110
|
+
!Task.isTaskTouched(taskToRun.preTask, touchedTasksArray)
|
|
111
|
+
) {
|
|
109
112
|
return Task.runTask(taskToRun.preTask, { x, touchedTasksArray });
|
|
110
113
|
} else {
|
|
111
114
|
const done2 = plugins.smartpromise.defer();
|
|
@@ -121,8 +124,14 @@ export class Task<T = undefined> {
|
|
|
121
124
|
}
|
|
122
125
|
})
|
|
123
126
|
.then((x) => {
|
|
124
|
-
if (
|
|
125
|
-
|
|
127
|
+
if (
|
|
128
|
+
taskToRun.afterTask &&
|
|
129
|
+
!Task.isTaskTouched(taskToRun.afterTask, touchedTasksArray)
|
|
130
|
+
) {
|
|
131
|
+
return Task.runTask(taskToRun.afterTask, {
|
|
132
|
+
x: x,
|
|
133
|
+
touchedTasksArray: touchedTasksArray,
|
|
134
|
+
});
|
|
126
135
|
} else {
|
|
127
136
|
const done2 = plugins.smartpromise.defer();
|
|
128
137
|
done2.resolve(x);
|
|
@@ -27,14 +27,18 @@ export class Taskchain extends Task {
|
|
|
27
27
|
let taskCounter = 0; // counter for iterating async over the taskArray
|
|
28
28
|
const iterateTasks = (x: any) => {
|
|
29
29
|
if (typeof this.taskArray[taskCounter] !== 'undefined') {
|
|
30
|
-
console.log(
|
|
30
|
+
console.log(
|
|
31
|
+
this.name + ' running: Task' + this.taskArray[taskCounter].name,
|
|
32
|
+
);
|
|
31
33
|
this.taskArray[taskCounter].trigger(x).then((x) => {
|
|
32
34
|
logger.log('info', this.taskArray[taskCounter].name);
|
|
33
35
|
taskCounter++;
|
|
34
36
|
iterateTasks(x);
|
|
35
37
|
});
|
|
36
38
|
} else {
|
|
37
|
-
console.log(
|
|
39
|
+
console.log(
|
|
40
|
+
'Taskchain "' + this.name + '" completed successfully',
|
|
41
|
+
);
|
|
38
42
|
done.resolve(x);
|
|
39
43
|
}
|
|
40
44
|
};
|
|
@@ -19,7 +19,9 @@ export class TaskDebounced<T = unknown> extends Task {
|
|
|
19
19
|
});
|
|
20
20
|
this.taskFunction = optionsArg.taskFunction;
|
|
21
21
|
this._observableIntake.observable
|
|
22
|
-
.pipe(
|
|
22
|
+
.pipe(
|
|
23
|
+
plugins.smartrx.rxjs.ops.debounceTime(optionsArg.debounceTimeInMillis),
|
|
24
|
+
)
|
|
23
25
|
.subscribe((x) => {
|
|
24
26
|
this.taskFunction(x);
|
|
25
27
|
});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import * as plugins from './taskbuffer.plugins.js';
|
|
2
2
|
import { Task } from './taskbuffer.classes.task.js';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
AbstractDistributedCoordinator,
|
|
5
|
+
type IDistributedTaskRequestResult,
|
|
6
|
+
} from './taskbuffer.classes.distributedcoordinator.js';
|
|
4
7
|
|
|
5
8
|
export interface ICronJob {
|
|
6
9
|
cronString: string;
|
|
@@ -66,7 +69,10 @@ export class TaskManager {
|
|
|
66
69
|
async (triggerTime: number) => {
|
|
67
70
|
this.logTaskState(task);
|
|
68
71
|
if (this.options.distributedCoordinator) {
|
|
69
|
-
const announcementResult = await this.performDistributedConsultation(
|
|
72
|
+
const announcementResult = await this.performDistributedConsultation(
|
|
73
|
+
task,
|
|
74
|
+
triggerTime,
|
|
75
|
+
);
|
|
70
76
|
if (!announcementResult.shouldTrigger) {
|
|
71
77
|
console.log('Distributed coordinator result: NOT EXECUTING');
|
|
72
78
|
return;
|
|
@@ -75,7 +81,7 @@ export class TaskManager {
|
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
83
|
await task.trigger();
|
|
78
|
-
}
|
|
84
|
+
},
|
|
79
85
|
);
|
|
80
86
|
task.cronJob = cronJob;
|
|
81
87
|
}
|
|
@@ -88,7 +94,10 @@ export class TaskManager {
|
|
|
88
94
|
console.log(`Task >>${task.name}<< is ${bufferState}`);
|
|
89
95
|
}
|
|
90
96
|
|
|
91
|
-
private async performDistributedConsultation(
|
|
97
|
+
private async performDistributedConsultation(
|
|
98
|
+
task: Task,
|
|
99
|
+
triggerTime: number,
|
|
100
|
+
): Promise<IDistributedTaskRequestResult> {
|
|
92
101
|
console.log('Found a distributed coordinator, performing consultation.');
|
|
93
102
|
|
|
94
103
|
return this.options.distributedCoordinator.fireDistributedTaskRequest({
|
|
@@ -5,7 +5,8 @@ import { Task } from './taskbuffer.classes.task.js';
|
|
|
5
5
|
export class TaskRunner {
|
|
6
6
|
public maxParrallelJobs: number = 1;
|
|
7
7
|
public status: 'stopped' | 'running' = 'stopped';
|
|
8
|
-
public runningTasks: plugins.lik.ObjectMap<Task> =
|
|
8
|
+
public runningTasks: plugins.lik.ObjectMap<Task> =
|
|
9
|
+
new plugins.lik.ObjectMap<Task>();
|
|
9
10
|
public qeuedTasks: Task[] = [];
|
|
10
11
|
|
|
11
12
|
constructor() {
|
package/ts/taskbuffer.plugins.ts
CHANGED
|
@@ -6,4 +6,12 @@ import * as smartrx from '@push.rocks/smartrx';
|
|
|
6
6
|
import * as smarttime from '@push.rocks/smarttime';
|
|
7
7
|
import * as smartunique from '@push.rocks/smartunique';
|
|
8
8
|
|
|
9
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
lik,
|
|
11
|
+
smartlog,
|
|
12
|
+
smartpromise,
|
|
13
|
+
smartdelay,
|
|
14
|
+
smartrx,
|
|
15
|
+
smarttime,
|
|
16
|
+
smartunique,
|
|
17
|
+
};
|