Compare commits

..

12 Commits

Author SHA1 Message Date
973678d635 3.0.6 2023-01-07 20:35:28 +01:00
28e7bad605 fix(core): update 2023-01-07 20:35:27 +01:00
fb44dd47fc 3.0.5 2023-01-07 19:05:30 +01:00
a2f6bccac2 fix(core): update 2023-01-07 19:05:29 +01:00
e4f8be5603 3.0.4 2022-11-14 14:54:26 +01:00
84f186924e fix(core): update 2022-11-14 14:54:26 +01:00
ff57dccee1 3.0.3 2022-11-09 10:36:18 +01:00
a9d84d5147 fix(core): update 2022-11-09 10:36:18 +01:00
ae6a6ce67e 3.0.2 2022-08-02 15:07:20 +02:00
05b14136f9 fix(core): update 2022-08-02 15:07:20 +02:00
bf9ca39c36 3.0.1 2022-04-15 16:41:42 +02:00
e61791ec41 fix(core): update 2022-04-15 16:41:42 +02:00
10 changed files with 4471 additions and 18486 deletions

18468
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/taskbuffer",
"version": "3.0.0",
"version": "3.0.6",
"private": false,
"description": "flexible task management. TypeScript ready!",
"main": "dist_ts/index.js",
@ -28,22 +28,21 @@
},
"homepage": "https://gitlab.com/pushrocks/taskbuffer#readme",
"dependencies": {
"@pushrocks/lik": "^5.0.4",
"@pushrocks/isounique": "^1.0.5",
"@pushrocks/lik": "^6.0.0",
"@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartlog": "^2.0.44",
"@pushrocks/smartlog": "^3.0.1",
"@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartrx": "^2.0.25",
"@pushrocks/smarttime": "^3.0.45",
"@types/cron": "^1.7.3"
"@pushrocks/smartrx": "^3.0.0",
"@pushrocks/smarttime": "^4.0.1"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.61",
"@gitzone/tsbundle": "^1.0.101",
"@gitzone/tstest": "^1.0.70",
"@pushrocks/tapbundle": "^5.0.3",
"@types/node": "^17.0.23",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
"@gitzone/tsbuild": "^2.1.63",
"@gitzone/tsbundle": "^2.0.6",
"@gitzone/tsrun": "^1.2.39",
"@gitzone/tstest": "^1.0.72",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.11.18"
},
"files": [
"ts/**/*",

4349
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/taskbuffer',
version: '3.0.6',
description: 'flexible task management. TypeScript ready!'
}

View File

@ -6,3 +6,7 @@ export { TaskManager } from './taskbuffer.classes.taskmanager.js';
export { TaskOnce } from './taskbuffer.classes.taskonce.js';
export { TaskRunner } from './taskbuffer.classes.taskrunner.js';
export { TaskDebounced } from './taskbuffer.classes.taskdebounced.js';
import * as distributedCoordination from './taskbuffer.classes.distributedcoordinator.js';
export {
distributedCoordination
}

View File

@ -0,0 +1,46 @@
import { Task } from './taskbuffer.classes.task.js';
import * as plugins from './taskbuffer.plugins.js';
/**
* constains all data for the final coordinator to actually make an informed decision
*/
export interface IDistributedDecisionInfoBasis {
submitterRandomId: string;
taskName: string;
taskVersion: string;
taskExecutionTime: number;
taskExecutionTimeout: number;
taskExecutionParallel: number;
status: 'requesting' | 'gotRejected' | 'failed' | 'succeeded';
}
export interface ITaskConsultationResult {
considered: boolean;
rank: string;
reason: string;
shouldTrigger: boolean;
}
export interface IDistributedCoordinatorConstructorOptions {
/**
* each execution should be announced
*/
announceDistributedDecisionInfoBasis: (distributedCoordinatorArg: DistributedCoordinator, infoBasisArg: IDistributedDecisionInfoBasis) => Promise<ITaskConsultationResult>
updateDistributedDecisionInfoBasis: (distributedCoordinatorArg: DistributedCoordinator, infoBasisArg: IDistributedDecisionInfoBasis) => Promise<void>
}
export class DistributedCoordinator {
public options: IDistributedCoordinatorConstructorOptions;
constructor(optionsArg: IDistributedCoordinatorConstructorOptions) {
this.options = optionsArg;
}
public async announceDistributedDecisionInfoBasis(infoBasisArg: IDistributedDecisionInfoBasis): Promise<ITaskConsultationResult> {
return this.options.announceDistributedDecisionInfoBasis(this, infoBasisArg);
}
public async updateDistributedDevisionInfoBasis(infoBasisArg: IDistributedDecisionInfoBasis): Promise<void> {
return this.options.updateDistributedDecisionInfoBasis(this, infoBasisArg)
}
}

View File

@ -128,12 +128,19 @@ export class Task {
// INSTANCE
// mandatory properties
public name: string;
/**
* the version of the task
* should follow semver
* might be important for DistributedCoordinator
*/
public version: string;
public taskFunction: ITaskFunction;
public buffered: boolean;
public cronJob: plugins.smarttime.CronJob;
public bufferMax: number;
public execDelay: number;
public timeout: number;
// tasks to run before and after
public preTask: Task | TPreOrAfterTaskFunction;

View File

@ -1,5 +1,6 @@
import * as plugins from './taskbuffer.plugins.js';
import { Task } from './taskbuffer.classes.task.js';
import { DistributedCoordinator } from './taskbuffer.classes.distributedcoordinator.js';
export interface ICronJob {
cronString: string;
@ -7,12 +8,21 @@ export interface ICronJob {
job: any;
}
export interface ITaskManagerConstructorOptions {
distributedCoordinator?: DistributedCoordinator
}
export class TaskManager {
public randomId = plugins.isounique.uni();
public taskMap = new plugins.lik.ObjectMap<Task>();
private cronJobManager = new plugins.smarttime.CronManager();
constructor() {
// nothing here
public options: ITaskManagerConstructorOptions = {
distributedCoordinator: null
};
constructor(optionosArg: ITaskManagerConstructorOptions = {}) {
this.options = Object.assign(this.options, optionosArg);
}
/**
@ -68,7 +78,7 @@ export class TaskManager {
*/
public scheduleTaskByName(taskNameArg: string, cronStringArg: string) {
const taskToSchedule = this.getTaskByName(taskNameArg);
const cronJob = this.cronJobManager.addCronjob(cronStringArg, async () => {
const cronJob = this.cronJobManager.addCronjob(cronStringArg, async (triggerTimeArg: number) => {
console.log(`taskbuffer schedule triggered task >>${taskToSchedule.name}<<`);
console.log(
`task >>${taskToSchedule.name}<< is ${
@ -77,6 +87,25 @@ export class TaskManager {
: `unbuffered`
}`
);
if (this.options.distributedCoordinator) {
console.log(`Found a distrubuted coordinator, performing distributed consultation.`);
const announcementResult = await this.options.distributedCoordinator.announceDistributedDecisionInfoBasis({
submitterRandomId: this.randomId,
status: 'requesting',
taskExecutionParallel: 1,
taskExecutionTime: triggerTimeArg,
taskExecutionTimeout: taskToSchedule.timeout,
taskName: taskToSchedule.name,
taskVersion: taskToSchedule.version,
});
if (!announcementResult.shouldTrigger) {
console.log('distributed coordinator result: NOT EXECUTING')
return;
} else {
console.log('distributed coordinator result: CHOSEN AND EXECUTING')
}
}
await taskToSchedule.trigger();
});
taskToSchedule.cronJob = cronJob;

View File

@ -1,8 +1,9 @@
import * as smartlog from '@pushrocks/smartlog';
import * as isounique from '@pushrocks/isounique';
import * as lik from '@pushrocks/lik';
import * as smartlog from '@pushrocks/smartlog';
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartdelay from '@pushrocks/smartdelay';
import * as smartrx from '@pushrocks/smartrx';
import * as smarttime from '@pushrocks/smarttime';
export { smartlog, lik, smartpromise, smartdelay, smartrx, smarttime };
export { isounique, lik, smartlog, smartpromise, smartdelay, smartrx, smarttime };

10
tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true
}
}