New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

node-taskflow

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-taskflow

A simple task execution framework with conditions

latest
npmnpm
Version
0.0.8
Version published
Maintainers
1
Created
Source

node-taskflow

A simple task flow execution framework based on conditions.

Installation

  npm i node-taskflow

Usage

Define your task function in separate files. For example, create a file named task1.js:

    // test.js in root directory
  export default function Task1(data) {  
    console.log('Executing Task1 with data:', data);  
  }
  // or extend base class to create task
import  {BaseTask}  from '../index';

export class MyTask extends BaseTask {
    condition(inputData: any): boolean {
        return inputData.someCondition; // Custom condition for the class
    }

    async execute(inputData: any): Promise<any> {
        console.log('Custom task execution with data:', inputData); // Custom task execution logic
    }
}


Define your task conditions in a yml file for function based task and for class based task we can define in class function only no need to define in yaml:

  # test.yml in root directory for function based
  settings:
    - logLevel: info
  tasks:
    - name: Task1
      function: 'test.js'
      conditions:
      - type: 'gt'
        property: 'dataValue'
        threshold: 150
  
    # test.yml in root directory for class based
  settings:
    - logLevel: info
  tasks:
    - name: Task1
      function: 'test.js'

Run the executor:

  // test.ts
  import { TaskFlow } from "node-taskflow";

  TaskFlow.configure('./test.yml').then(() => {
    const inputData = {dataValue: 300};
    TaskFlow.execute(inputData);    
  });

   // or 

  await TaskFlow.configure('./test.yml')
    
  const inputData = {dataValue: 300};
  TaskFlow.execute(inputData);    
  

The executor will read the configuration from tasks-config.yml, execute the matching task based on conditions, and log the result.

Development

  • Clone this repository:
    git clone https://github.com/vectoscalar/node-taskflow
    cd node-taskflow
    
  • Install dependencies:
    npm install
    
  • test:
    npm run test
    

Pending

  • Add Zod (https://github.com/colinhacks/zod) for validation of yml.
  • curently only default exported function is supported. pick function from the name field in yml. check process of registraton.
  • Add proper logs
  • Add functionality of nextTask [low priority]
  • Add functionality of taskType (task, wait etc.) default type will be task [low priority]
  • Add description property with task

FAQs

Package last updated on 01 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts