fix(core): update

This commit is contained in:
Philipp Kunz 2023-01-07 19:05:29 +01:00
parent e4f8be5603
commit a2f6bccac2
6 changed files with 239 additions and 203 deletions

View File

@ -28,12 +28,13 @@
}, },
"homepage": "https://gitlab.com/pushrocks/taskbuffer#readme", "homepage": "https://gitlab.com/pushrocks/taskbuffer#readme",
"dependencies": { "dependencies": {
"@pushrocks/isounique": "^1.0.5",
"@pushrocks/lik": "^6.0.0", "@pushrocks/lik": "^6.0.0",
"@pushrocks/smartdelay": "^2.0.13", "@pushrocks/smartdelay": "^2.0.13",
"@pushrocks/smartlog": "^3.0.1", "@pushrocks/smartlog": "^3.0.1",
"@pushrocks/smartpromise": "^3.1.7", "@pushrocks/smartpromise": "^3.1.7",
"@pushrocks/smartrx": "^3.0.0", "@pushrocks/smartrx": "^3.0.0",
"@pushrocks/smarttime": "^3.0.45" "@pushrocks/smarttime": "^4.0.1"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.63", "@gitzone/tsbuild": "^2.1.63",
@ -41,7 +42,7 @@
"@gitzone/tsrun": "^1.2.39", "@gitzone/tsrun": "^1.2.39",
"@gitzone/tstest": "^1.0.72", "@gitzone/tstest": "^1.0.72",
"@pushrocks/tapbundle": "^5.0.4", "@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^18.6.3" "@types/node": "^18.11.18"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

403
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@pushrocks/taskbuffer', name: '@pushrocks/taskbuffer',
version: '3.0.4', version: '3.0.5',
description: 'flexible task management. TypeScript ready!' description: 'flexible task management. TypeScript ready!'
} }

View File

@ -5,6 +5,7 @@ import * as plugins from './taskbuffer.plugins.js';
* constains all data for the final coordinator to actually make an informed decision * constains all data for the final coordinator to actually make an informed decision
*/ */
export interface IDistributedDecisionInfoBasis { export interface IDistributedDecisionInfoBasis {
submitterRandomId: string;
taskName: string; taskName: string;
taskVersion: string; taskVersion: string;
taskExecutionTime: number; taskExecutionTime: number;
@ -21,8 +22,11 @@ export interface ITaskConsultationResult {
} }
export interface IDistributedCoordinatorConstructorOptions { export interface IDistributedCoordinatorConstructorOptions {
announceDistributedDecisionInfoBasis: (infoBasisArg: IDistributedDecisionInfoBasis) => Promise<ITaskConsultationResult> /**
updateDistributedDecisionInfoBasis: (infoBasisArg: IDistributedDecisionInfoBasis) => Promise<void> * each execution should be announced
*/
announceDistributedDecisionInfoBasis: (distributedCoordinatorArg: DistributedCoordinator, infoBasisArg: IDistributedDecisionInfoBasis) => Promise<ITaskConsultationResult>
updateDistributedDecisionInfoBasis: (distributedCoordinatorArg: DistributedCoordinator, infoBasisArg: IDistributedDecisionInfoBasis) => Promise<void>
} }
export class DistributedCoordinator { export class DistributedCoordinator {
@ -33,10 +37,10 @@ export class DistributedCoordinator {
} }
public async announceDistributedDecisionInfoBasis(infoBasisArg: IDistributedDecisionInfoBasis): Promise<ITaskConsultationResult> { public async announceDistributedDecisionInfoBasis(infoBasisArg: IDistributedDecisionInfoBasis): Promise<ITaskConsultationResult> {
return this.options.announceDistributedDecisionInfoBasis(infoBasisArg); return this.options.announceDistributedDecisionInfoBasis(this, infoBasisArg);
} }
public async updateDistributedDevisionInfoBasis(infoBasisArg: IDistributedDecisionInfoBasis): Promise<void> { public async updateDistributedDevisionInfoBasis(infoBasisArg: IDistributedDecisionInfoBasis): Promise<void> {
return this.options.updateDistributedDecisionInfoBasis(infoBasisArg) return this.options.updateDistributedDecisionInfoBasis(this, infoBasisArg)
} }
} }

View File

@ -13,6 +13,7 @@ export interface ITaskManagerConstructorOptions {
} }
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();
@ -20,7 +21,7 @@ export class TaskManager {
distributedCoordinator: null distributedCoordinator: null
}; };
constructor(optionosArg: ITaskManagerConstructorOptions) { constructor(optionosArg: ITaskManagerConstructorOptions = {}) {
this.options = Object.assign(this.options, optionosArg); this.options = Object.assign(this.options, optionosArg);
} }
@ -88,14 +89,22 @@ export class TaskManager {
); );
if (this.options.distributedCoordinator) { if (this.options.distributedCoordinator) {
console.log(`Found a distrubuted coordinator, performing distributed consultation.`); console.log(`Found a distrubuted coordinator, performing distributed consultation.`);
const announcementResult = this.options.distributedCoordinator.announceDistributedDecisionInfoBasis({ const announcementResult = await this.options.distributedCoordinator.announceDistributedDecisionInfoBasis({
submitterRandomId: this.randomId,
status: 'requesting', status: 'requesting',
taskExecutionParallel: 1, taskExecutionParallel: 1,
taskExecutionTime: triggerTimeArg, taskExecutionTime: triggerTimeArg,
taskExecutionTimeout: taskToSchedule.timeout, taskExecutionTimeout: taskToSchedule.timeout,
taskName: taskToSchedule.name, taskName: taskToSchedule.name,
taskVersion: taskToSchedule.version, 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();
}); });

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 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 };