Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
5bf568d0cd | |||
173e1ca35d | |||
ce258c76d2 | |||
4d2756b743 | |||
973678d635 | |||
28e7bad605 | |||
fb44dd47fc | |||
a2f6bccac2 | |||
e4f8be5603 | |||
84f186924e | |||
ff57dccee1 | |||
a9d84d5147 | |||
ae6a6ce67e | |||
05b14136f9 |
18436
package-lock.json
generated
18436
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/taskbuffer",
|
"name": "@pushrocks/taskbuffer",
|
||||||
"version": "3.0.1",
|
"version": "3.0.8",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "flexible task management. TypeScript ready!",
|
"description": "flexible task management. TypeScript ready!",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -28,21 +28,21 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/taskbuffer#readme",
|
"homepage": "https://gitlab.com/pushrocks/taskbuffer#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^5.0.4",
|
"@pushrocks/isounique": "^1.0.5",
|
||||||
|
"@pushrocks/lik": "^6.0.0",
|
||||||
"@pushrocks/smartdelay": "^2.0.13",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartlog": "^2.0.44",
|
"@pushrocks/smartlog": "^3.0.1",
|
||||||
"@pushrocks/smartpromise": "^3.1.7",
|
"@pushrocks/smartpromise": "^3.1.7",
|
||||||
"@pushrocks/smartrx": "^2.0.25",
|
"@pushrocks/smartrx": "^3.0.0",
|
||||||
"@pushrocks/smarttime": "^3.0.45"
|
"@pushrocks/smarttime": "^4.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.61",
|
"@gitzone/tsbuild": "^2.1.63",
|
||||||
"@gitzone/tsbundle": "^1.0.101",
|
"@gitzone/tsbundle": "^2.0.6",
|
||||||
"@gitzone/tstest": "^1.0.70",
|
"@gitzone/tsrun": "^1.2.39",
|
||||||
"@pushrocks/tapbundle": "^5.0.3",
|
"@gitzone/tstest": "^1.0.72",
|
||||||
"@types/node": "^17.0.23",
|
"@pushrocks/tapbundle": "^5.0.4",
|
||||||
"tslint": "^6.1.3",
|
"@types/node": "^18.11.18"
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
4349
pnpm-lock.yaml
generated
Normal file
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
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@pushrocks/taskbuffer',
|
||||||
|
version: '3.0.8',
|
||||||
|
description: 'flexible task management. TypeScript ready!'
|
||||||
|
}
|
@ -6,3 +6,7 @@ export { TaskManager } from './taskbuffer.classes.taskmanager.js';
|
|||||||
export { TaskOnce } from './taskbuffer.classes.taskonce.js';
|
export { TaskOnce } from './taskbuffer.classes.taskonce.js';
|
||||||
export { TaskRunner } from './taskbuffer.classes.taskrunner.js';
|
export { TaskRunner } from './taskbuffer.classes.taskrunner.js';
|
||||||
export { TaskDebounced } from './taskbuffer.classes.taskdebounced.js';
|
export { TaskDebounced } from './taskbuffer.classes.taskdebounced.js';
|
||||||
|
import * as distributedCoordination from './taskbuffer.classes.distributedcoordinator.js';
|
||||||
|
export {
|
||||||
|
distributedCoordination
|
||||||
|
}
|
||||||
|
34
ts/taskbuffer.classes.distributedcoordinator.ts
Normal file
34
ts/taskbuffer.classes.distributedcoordinator.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
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 {
|
||||||
|
/**
|
||||||
|
* this needs to correlate to the consultationResult
|
||||||
|
*/
|
||||||
|
submitterRandomId: string;
|
||||||
|
taskName: string;
|
||||||
|
taskVersion: string;
|
||||||
|
taskExecutionTime: number;
|
||||||
|
taskExecutionTimeout: number;
|
||||||
|
taskExecutionParallel: number;
|
||||||
|
status: 'requesting' | 'gotRejected' | 'failed' | 'succeeded';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IDsitributedTaskConsultationResult {
|
||||||
|
/**
|
||||||
|
* this needs to correlate to the decisionInfoBasis
|
||||||
|
*/
|
||||||
|
submitterRandomId: string;
|
||||||
|
considered: boolean;
|
||||||
|
rank: string;
|
||||||
|
reason: string;
|
||||||
|
shouldTrigger: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class AbstractDistributedCoordinator {
|
||||||
|
public abstract announceDistributedDecisionInfoBasis(infoBasisArg: IDistributedDecisionInfoBasis): Promise<IDsitributedTaskConsultationResult>
|
||||||
|
public abstract updateDistributedDevisionInfoBasis(infoBasisArg: IDistributedDecisionInfoBasis): Promise<void>
|
||||||
|
}
|
@ -128,12 +128,19 @@ export class Task {
|
|||||||
// INSTANCE
|
// INSTANCE
|
||||||
// mandatory properties
|
// mandatory properties
|
||||||
public name: string;
|
public name: string;
|
||||||
|
/**
|
||||||
|
* the version of the task
|
||||||
|
* should follow semver
|
||||||
|
* might be important for DistributedCoordinator
|
||||||
|
*/
|
||||||
|
public version: string;
|
||||||
public taskFunction: ITaskFunction;
|
public taskFunction: ITaskFunction;
|
||||||
public buffered: boolean;
|
public buffered: boolean;
|
||||||
public cronJob: plugins.smarttime.CronJob;
|
public cronJob: plugins.smarttime.CronJob;
|
||||||
|
|
||||||
public bufferMax: number;
|
public bufferMax: number;
|
||||||
public execDelay: number;
|
public execDelay: number;
|
||||||
|
public timeout: number;
|
||||||
|
|
||||||
// tasks to run before and after
|
// tasks to run before and after
|
||||||
public preTask: Task | TPreOrAfterTaskFunction;
|
public preTask: Task | TPreOrAfterTaskFunction;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import * as plugins from './taskbuffer.plugins.js';
|
import * as plugins from './taskbuffer.plugins.js';
|
||||||
import { Task } from './taskbuffer.classes.task.js';
|
import { Task } from './taskbuffer.classes.task.js';
|
||||||
|
import { AbstractDistributedCoordinator } from './taskbuffer.classes.distributedcoordinator.js';
|
||||||
|
|
||||||
export interface ICronJob {
|
export interface ICronJob {
|
||||||
cronString: string;
|
cronString: string;
|
||||||
@ -7,12 +8,21 @@ export interface ICronJob {
|
|||||||
job: any;
|
job: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ITaskManagerConstructorOptions {
|
||||||
|
distributedCoordinator?: AbstractDistributedCoordinator
|
||||||
|
}
|
||||||
|
|
||||||
export class TaskManager {
|
export class TaskManager {
|
||||||
|
public randomId = plugins.isounique.uni();
|
||||||
public taskMap = new plugins.lik.ObjectMap<Task>();
|
public taskMap = new plugins.lik.ObjectMap<Task>();
|
||||||
private cronJobManager = new plugins.smarttime.CronManager();
|
private cronJobManager = new plugins.smarttime.CronManager();
|
||||||
|
|
||||||
constructor() {
|
public options: ITaskManagerConstructorOptions = {
|
||||||
// nothing here
|
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) {
|
public scheduleTaskByName(taskNameArg: string, cronStringArg: string) {
|
||||||
const taskToSchedule = this.getTaskByName(taskNameArg);
|
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(`taskbuffer schedule triggered task >>${taskToSchedule.name}<<`);
|
||||||
console.log(
|
console.log(
|
||||||
`task >>${taskToSchedule.name}<< is ${
|
`task >>${taskToSchedule.name}<< is ${
|
||||||
@ -77,6 +87,25 @@ export class TaskManager {
|
|||||||
: `unbuffered`
|
: `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();
|
await taskToSchedule.trigger();
|
||||||
});
|
});
|
||||||
taskToSchedule.cronJob = cronJob;
|
taskToSchedule.cronJob = cronJob;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as isounique from '@pushrocks/isounique';
|
||||||
import * as lik from '@pushrocks/lik';
|
import * as lik from '@pushrocks/lik';
|
||||||
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
import * as smartrx from '@pushrocks/smartrx';
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
import * as smarttime from '@pushrocks/smarttime';
|
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
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user