Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
e4f8be5603 | |||
84f186924e | |||
ff57dccee1 | |||
a9d84d5147 | |||
ae6a6ce67e | |||
05b14136f9 | |||
bf9ca39c36 | |||
e61791ec41 |
18468
package-lock.json
generated
18468
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",
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.4",
|
||||
"private": false,
|
||||
"description": "flexible task management. TypeScript ready!",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -28,22 +28,20 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/taskbuffer#readme",
|
||||
"dependencies": {
|
||||
"@pushrocks/lik": "^5.0.4",
|
||||
"@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": "^3.0.45"
|
||||
},
|
||||
"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.6.3"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
4328
pnpm-lock.yaml
generated
Normal file
4328
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.4',
|
||||
description: 'flexible task management. TypeScript ready!'
|
||||
}
|
42
ts/taskbuffer.classes.distributedcoordinator.ts
Normal file
42
ts/taskbuffer.classes.distributedcoordinator.ts
Normal file
@ -0,0 +1,42 @@
|
||||
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 {
|
||||
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 {
|
||||
announceDistributedDecisionInfoBasis: (infoBasisArg: IDistributedDecisionInfoBasis) => Promise<ITaskConsultationResult>
|
||||
updateDistributedDecisionInfoBasis: (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(infoBasisArg);
|
||||
}
|
||||
public async updateDistributedDevisionInfoBasis(infoBasisArg: IDistributedDecisionInfoBasis): Promise<void> {
|
||||
return this.options.updateDistributedDecisionInfoBasis(infoBasisArg)
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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,20 @@ export interface ICronJob {
|
||||
job: any;
|
||||
}
|
||||
|
||||
export interface ITaskManagerConstructorOptions {
|
||||
distributedCoordinator?: DistributedCoordinator
|
||||
}
|
||||
|
||||
export class TaskManager {
|
||||
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 +77,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 +86,17 @@ export class TaskManager {
|
||||
: `unbuffered`
|
||||
}`
|
||||
);
|
||||
if (this.options.distributedCoordinator) {
|
||||
console.log(`Found a distrubuted coordinator, performing distributed consultation.`);
|
||||
const announcementResult = this.options.distributedCoordinator.announceDistributedDecisionInfoBasis({
|
||||
status: 'requesting',
|
||||
taskExecutionParallel: 1,
|
||||
taskExecutionTime: triggerTimeArg,
|
||||
taskExecutionTimeout: taskToSchedule.timeout,
|
||||
taskName: taskToSchedule.name,
|
||||
taskVersion: taskToSchedule.version,
|
||||
})
|
||||
}
|
||||
await taskToSchedule.trigger();
|
||||
});
|
||||
taskToSchedule.cronJob = cronJob;
|
||||
|
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