fix(tests): Update CI workflows, fix tests and refresh README/package metadata
This commit is contained in:
		@@ -3,6 +3,6 @@
 | 
			
		||||
 */
 | 
			
		||||
export const commitinfo = {
 | 
			
		||||
  name: '@push.rocks/taskbuffer',
 | 
			
		||||
  version: '3.1.8',
 | 
			
		||||
  version: '3.1.9',
 | 
			
		||||
  description: 'A flexible task management library supporting TypeScript, allowing for task buffering, scheduling, and execution with dependency management.'
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -13,9 +13,8 @@ export class BufferRunner {
 | 
			
		||||
    if (!(this.bufferCounter >= this.task.bufferMax)) {
 | 
			
		||||
      this.bufferCounter++;
 | 
			
		||||
    }
 | 
			
		||||
    const returnPromise: Promise<any> = this.task.cycleCounter.getPromiseForCycle(
 | 
			
		||||
      this.bufferCounter
 | 
			
		||||
    );
 | 
			
		||||
    const returnPromise: Promise<any> =
 | 
			
		||||
      this.task.cycleCounter.getPromiseForCycle(this.bufferCounter);
 | 
			
		||||
    if (!this.task.running) {
 | 
			
		||||
      this._run(x);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -26,11 +26,11 @@ export interface IDistributedTaskRequestResult {
 | 
			
		||||
 | 
			
		||||
export abstract class AbstractDistributedCoordinator {
 | 
			
		||||
  public abstract fireDistributedTaskRequest(
 | 
			
		||||
    infoBasis: IDistributedTaskRequest
 | 
			
		||||
    infoBasis: IDistributedTaskRequest,
 | 
			
		||||
  ): Promise<IDistributedTaskRequestResult>;
 | 
			
		||||
 | 
			
		||||
  public abstract updateDistributedTaskRequest(
 | 
			
		||||
    infoBasis: IDistributedTaskRequest
 | 
			
		||||
    infoBasis: IDistributedTaskRequest,
 | 
			
		||||
  ): Promise<void>;
 | 
			
		||||
 | 
			
		||||
  public abstract start(): Promise<void>;
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@ export type TPreOrAfterTaskFunction = () => Task<any>;
 | 
			
		||||
 | 
			
		||||
export class Task<T = undefined> {
 | 
			
		||||
  public static extractTask<T = undefined>(
 | 
			
		||||
    preOrAfterTaskArg: Task<T> | TPreOrAfterTaskFunction
 | 
			
		||||
    preOrAfterTaskArg: Task<T> | TPreOrAfterTaskFunction,
 | 
			
		||||
  ): Task<T> {
 | 
			
		||||
    switch (true) {
 | 
			
		||||
      case !preOrAfterTaskArg:
 | 
			
		||||
@@ -47,7 +47,7 @@ export class Task<T = undefined> {
 | 
			
		||||
 | 
			
		||||
  public static isTaskTouched<T = undefined>(
 | 
			
		||||
    taskArg: Task<T> | TPreOrAfterTaskFunction,
 | 
			
		||||
    touchedTasksArray: Task<T>[]
 | 
			
		||||
    touchedTasksArray: Task<T>[],
 | 
			
		||||
  ): boolean {
 | 
			
		||||
    const taskToCheck = Task.extractTask(taskArg);
 | 
			
		||||
    let result = false;
 | 
			
		||||
@@ -61,7 +61,7 @@ export class Task<T = undefined> {
 | 
			
		||||
 | 
			
		||||
  public static runTask = async <T>(
 | 
			
		||||
    taskArg: Task<T> | TPreOrAfterTaskFunction,
 | 
			
		||||
    optionsArg: { x?: any; touchedTasksArray?: Task<T>[] }
 | 
			
		||||
    optionsArg: { x?: any; touchedTasksArray?: Task<T>[] },
 | 
			
		||||
  ) => {
 | 
			
		||||
    const taskToRun = Task.extractTask(taskArg);
 | 
			
		||||
    const done = plugins.smartpromise.defer();
 | 
			
		||||
@@ -105,7 +105,10 @@ export class Task<T = undefined> {
 | 
			
		||||
    const localDeferred = plugins.smartpromise.defer();
 | 
			
		||||
    localDeferred.promise
 | 
			
		||||
      .then(() => {
 | 
			
		||||
        if (taskToRun.preTask && !Task.isTaskTouched(taskToRun.preTask, touchedTasksArray)) {
 | 
			
		||||
        if (
 | 
			
		||||
          taskToRun.preTask &&
 | 
			
		||||
          !Task.isTaskTouched(taskToRun.preTask, touchedTasksArray)
 | 
			
		||||
        ) {
 | 
			
		||||
          return Task.runTask(taskToRun.preTask, { x, touchedTasksArray });
 | 
			
		||||
        } else {
 | 
			
		||||
          const done2 = plugins.smartpromise.defer();
 | 
			
		||||
@@ -121,8 +124,14 @@ export class Task<T = undefined> {
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
      .then((x) => {
 | 
			
		||||
        if (taskToRun.afterTask && !Task.isTaskTouched(taskToRun.afterTask, touchedTasksArray)) {
 | 
			
		||||
          return Task.runTask(taskToRun.afterTask, { x: x, touchedTasksArray: touchedTasksArray });
 | 
			
		||||
        if (
 | 
			
		||||
          taskToRun.afterTask &&
 | 
			
		||||
          !Task.isTaskTouched(taskToRun.afterTask, touchedTasksArray)
 | 
			
		||||
        ) {
 | 
			
		||||
          return Task.runTask(taskToRun.afterTask, {
 | 
			
		||||
            x: x,
 | 
			
		||||
            touchedTasksArray: touchedTasksArray,
 | 
			
		||||
          });
 | 
			
		||||
        } else {
 | 
			
		||||
          const done2 = plugins.smartpromise.defer();
 | 
			
		||||
          done2.resolve(x);
 | 
			
		||||
 
 | 
			
		||||
@@ -27,14 +27,18 @@ export class Taskchain extends Task {
 | 
			
		||||
          let taskCounter = 0; // counter for iterating async over the taskArray
 | 
			
		||||
          const iterateTasks = (x: any) => {
 | 
			
		||||
            if (typeof this.taskArray[taskCounter] !== 'undefined') {
 | 
			
		||||
              console.log(this.name + ' running: Task' + this.taskArray[taskCounter].name);
 | 
			
		||||
              console.log(
 | 
			
		||||
                this.name + ' running: Task' + this.taskArray[taskCounter].name,
 | 
			
		||||
              );
 | 
			
		||||
              this.taskArray[taskCounter].trigger(x).then((x) => {
 | 
			
		||||
                logger.log('info', this.taskArray[taskCounter].name);
 | 
			
		||||
                taskCounter++;
 | 
			
		||||
                iterateTasks(x);
 | 
			
		||||
              });
 | 
			
		||||
            } else {
 | 
			
		||||
              console.log('Taskchain "' + this.name + '" completed successfully');
 | 
			
		||||
              console.log(
 | 
			
		||||
                'Taskchain "' + this.name + '" completed successfully',
 | 
			
		||||
              );
 | 
			
		||||
              done.resolve(x);
 | 
			
		||||
            }
 | 
			
		||||
          };
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,9 @@ export class TaskDebounced<T = unknown> extends Task {
 | 
			
		||||
    });
 | 
			
		||||
    this.taskFunction = optionsArg.taskFunction;
 | 
			
		||||
    this._observableIntake.observable
 | 
			
		||||
      .pipe(plugins.smartrx.rxjs.ops.debounceTime(optionsArg.debounceTimeInMillis))
 | 
			
		||||
      .pipe(
 | 
			
		||||
        plugins.smartrx.rxjs.ops.debounceTime(optionsArg.debounceTimeInMillis),
 | 
			
		||||
      )
 | 
			
		||||
      .subscribe((x) => {
 | 
			
		||||
        this.taskFunction(x);
 | 
			
		||||
      });
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,9 @@
 | 
			
		||||
import * as plugins from './taskbuffer.plugins.js';
 | 
			
		||||
import { Task } from './taskbuffer.classes.task.js';
 | 
			
		||||
import { AbstractDistributedCoordinator, type IDistributedTaskRequestResult } from './taskbuffer.classes.distributedcoordinator.js';
 | 
			
		||||
import {
 | 
			
		||||
  AbstractDistributedCoordinator,
 | 
			
		||||
  type IDistributedTaskRequestResult,
 | 
			
		||||
} from './taskbuffer.classes.distributedcoordinator.js';
 | 
			
		||||
 | 
			
		||||
export interface ICronJob {
 | 
			
		||||
  cronString: string;
 | 
			
		||||
@@ -66,7 +69,10 @@ export class TaskManager {
 | 
			
		||||
      async (triggerTime: number) => {
 | 
			
		||||
        this.logTaskState(task);
 | 
			
		||||
        if (this.options.distributedCoordinator) {
 | 
			
		||||
          const announcementResult = await this.performDistributedConsultation(task, triggerTime);
 | 
			
		||||
          const announcementResult = await this.performDistributedConsultation(
 | 
			
		||||
            task,
 | 
			
		||||
            triggerTime,
 | 
			
		||||
          );
 | 
			
		||||
          if (!announcementResult.shouldTrigger) {
 | 
			
		||||
            console.log('Distributed coordinator result: NOT EXECUTING');
 | 
			
		||||
            return;
 | 
			
		||||
@@ -75,7 +81,7 @@ export class TaskManager {
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        await task.trigger();
 | 
			
		||||
      }
 | 
			
		||||
      },
 | 
			
		||||
    );
 | 
			
		||||
    task.cronJob = cronJob;
 | 
			
		||||
  }
 | 
			
		||||
@@ -88,7 +94,10 @@ export class TaskManager {
 | 
			
		||||
    console.log(`Task >>${task.name}<< is ${bufferState}`);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private async performDistributedConsultation(task: Task, triggerTime: number): Promise<IDistributedTaskRequestResult> {
 | 
			
		||||
  private async performDistributedConsultation(
 | 
			
		||||
    task: Task,
 | 
			
		||||
    triggerTime: number,
 | 
			
		||||
  ): Promise<IDistributedTaskRequestResult> {
 | 
			
		||||
    console.log('Found a distributed coordinator, performing consultation.');
 | 
			
		||||
 | 
			
		||||
    return this.options.distributedCoordinator.fireDistributedTaskRequest({
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,8 @@ import { Task } from './taskbuffer.classes.task.js';
 | 
			
		||||
export class TaskRunner {
 | 
			
		||||
  public maxParrallelJobs: number = 1;
 | 
			
		||||
  public status: 'stopped' | 'running' = 'stopped';
 | 
			
		||||
  public runningTasks: plugins.lik.ObjectMap<Task> = new plugins.lik.ObjectMap<Task>();
 | 
			
		||||
  public runningTasks: plugins.lik.ObjectMap<Task> =
 | 
			
		||||
    new plugins.lik.ObjectMap<Task>();
 | 
			
		||||
  public qeuedTasks: Task[] = [];
 | 
			
		||||
 | 
			
		||||
  constructor() {
 | 
			
		||||
 
 | 
			
		||||
@@ -6,4 +6,12 @@ import * as smartrx from '@push.rocks/smartrx';
 | 
			
		||||
import * as smarttime from '@push.rocks/smarttime';
 | 
			
		||||
import * as smartunique from '@push.rocks/smartunique';
 | 
			
		||||
 | 
			
		||||
export { lik, smartlog, smartpromise, smartdelay, smartrx, smarttime, smartunique };
 | 
			
		||||
export {
 | 
			
		||||
  lik,
 | 
			
		||||
  smartlog,
 | 
			
		||||
  smartpromise,
 | 
			
		||||
  smartdelay,
 | 
			
		||||
  smartrx,
 | 
			
		||||
  smarttime,
 | 
			
		||||
  smartunique,
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user