Git Product home page Git Product logo

danielduarte / flowed Goto Github PK

View Code? Open in Web Editor NEW
138.0 13.0 18.0 1.7 MB

A fast and reliable flow engine for orchestration and more uses in Node.js, Deno and the browser

Home Page: https://danielduarte.github.io/flowed

License: MIT License

TypeScript 97.08% HTML 1.90% JavaScript 1.01%
flowframework flow task-manager task-runner flowengine flow-engine flow-execution flow-specifications process workflow

flowed's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flowed's Issues

Result Post-processing

Optional results post-processing to make possible some simple processing without adding more tasks.
Examples of processing:

  • Extract a field from an object
  • Create an object from a value
  • Create a string from a value
  • Convert an object into another one

Select next task

Maybe I don't understand this moment from docs, but can change next task from current?

For example, taskA ended and now result = 1, and now flow go to TaskB, at next time on end TaskA result = 2 and now flow go to TaskC. How I can realize this flow with flowed?

Console error misleading when a resolver does not have a return statement.

When a resolver does not have a return statement, the following error appears in console, misleading on the proper way to solve the issue:

(node:56642) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'hasOwnProperty' of undefined
    at Task.mapResultsFromResolver (/.../node_modules/flowed/dist/engine/task.js:113:31)
    at /.../node_modules/flowed/dist/engine/task.js:57:38

Transaction support

Add transaction support to group tasks into an atomic, undoable transaction.

Resolver as a functional component?

Is your feature request related to a problem? Please describe.
I need to cal useQuery apollo hook and with resolvers as class components I am not able to do so.

Describe the solution you'd like
Library should accept resolver as simple functions also.

Describe alternatives you've considered
I tried to write resolver as a functional component but then it failed with error like "this.taskResolverConstructor is not a constructor".

Feeding the Conditional resolver true/false results without using parameters

From the examples I have looked over and the testing I have run, it does not appear that trueResult/FalseResult parameters can be set to a hardcoded line of text, but have to be fed their values from an entry in the parameter object.

If you have a flow spec with multiple conditionals which each have different true/false results, it would be easier to be able to write those directly in the params instead of having to feed in multiple different key/value pairs in hte parameters object.

Ex.

          resolver: {
            name: 'flowed::Conditional',
            params: { condition: 'intervalsCreated', trueResult: 'This is the text for true' , falseResult: 'This is the text for false' },
            results: {onTrue: 'ontrue', onFalse: 'onfalse'},
          },

And/or also being able to reference values in the context object

Ex.

        resolver: {
          name: 'flowed::Conditional',
          params: { condition: 'intervalsCreated', trueResult: 'context.context_true' , falseResult: 'context.context_false' },
          results: {onTrue: 'ontrue', onFalse: 'onfalse'},
        },

When using an async resolver which uses the fetch method to access an external endpoint the running flow is immediately interrupted

When using an async resolver which uses the fetch method to access an external endpoint the running flow is immediately interrupted and returns the control to the caller function without completing the tasks.

export function query_similar(query: string, filters: string) {
    return new Promise(async (resolve, reject) => {
        try {
            /* Call Clean API on the Front End API to reload the definition */
            const similar = "https://query-data.azurewebsites.net/api/similar?" + new URLSearchParams(
            {
                'op': "query",
                'query': query,
                "max_results": "10"
            });

           let response = await fetch(similar, {
                method: "GET",
                headers: {
                    "Content-Type": "application/json",
                }
            });

           const body = await response.json();
            
            if (body === undefined) {
                throw new Error(`Failed to call function: ${response.statusText}`);
            }
            resolve(body);
        } catch (error) {
            reject(error); // Reject the promise if an error occurs
        }
    });                           
}

async nlp_rank(item_id_field: string, records: any[], user_message:string) {
    if (isNotNull(records) && records.length > 0 && isNotNull(user_message)) {
      try {
        let id_list:string = records.map(record => record[item_id_field]).join(",");
        // call api to retrieve similarity ranking 
        const ranked_records = await query_similar(user_message, id_list);
        // merge arrays by document id
        let out_records = records.map((record, i) => Object.assign({}, record, ranked_records));     
        return out_records;
      } catch (error) {
        return;
      }
    }
  }

// This is the resolver class
export class ContentRank {
  async exec(params: ValueMap, context:ValueMap) {
    // simplified code

    records = await nlp_rank(item_id_field, input_records.records, userProfile.message);
    return { results: { records: records } };
  }
}

let results = await FlowManager.run(
        // The flow spec
        ret.strategy,          
        // The parameters
        ret.params,
        // The expected results
        [ out ],          
        // The resolvers mapping
        {
          load: Load as unknown as TaskResolverExecutor,
          filter: Filter as unknown as TaskResolverExecutor,
          contentrank: ContentRank as unknown as TaskResolverExecutor,
          similarrank: SimilarRank as unknown as TaskResolverExecutor,
          top: Top as unknown as TaskResolverExecutor,
          sort: Sort as unknown as TaskResolverExecutor,
          merge: Merge as unknown as TaskResolverExecutor
        },
        { webAPI: this.context, registry: this.registry, userManager},
      );

Without the async resolver the workflow completes correctly, I suspect I'm doing some mistake with await async into the chain of function calls but really struggling to find where it could be.

Built-in Stop & Pause resolvers

Have a built-in stop and pause resolver.
Ideas in code:

// Stops the flow execution
export class StopResolver {
public async exec(params: GenericValueMap, task: Task, flow: Flow): Promise {
const validSignals = ['term', 'kill'];

const signal = params.signal || 'term';

if (validSignals.indexOf(params.signal) === -1) {
  throw new Error(`Not a valid flow termination signal: ${params.signal}. Valid signals are: [${validSignals.join(', ')}].`);
}

// @todo implement flow.term()
// @todo implement flow.stop()
const flowResult = await flow[signal]();

return { results: flowResult };

}
}

Create Multi-Task built-in resolver

Create a built-in task resolver to repeat a task execution using different params each time.
The input of the resolver would be an array of params.
The resolver would execute input.length times.
The output would be the array of results ordered in the same order as the params in the input array.

Notify when flow does not satisfies the expected result.

Right now, when executing the flow, we specify the desired results in the third parameter, for example

const response = await FlowManager.run(
      flowDefinition,
      parameters,
      ['myResponse'],
      resolvers,
);

But, when for whatever reason (for example a cyclic flow or and unintended incorrect flow), the flow ends and it does not have a myResponse property.

It would be ideal if you can notify of such cases so the rest of the code can react accordingly.

what is the difference between 'provides' and 'results' ?

getDate: {
      provides: ['date'],
      resolver: {
        name: 'flowed::Echo',
        params: { in: { value: new Date() } },
        results: { out: 'date' },
      }
},

In the above configuration, what is the difference between provides and results ? Is it about task level and resolver level configuration?

Allow to directly pass values in the flow definition itself

It would be ideally to have the ability to pass some values for the tasks in the definition.

const flowDefinition = {
  tasks: {
    A: {
      requires: ['param1'],  
      provides: ['response'],
      resolver: {
        name: 'direct',
        params: { 
          param1: 'param1', // this one will be provided in the "run" method second parameter.
          param2: {value: '123'} // this one is directly defined in the flow. 
        },
        results: { b: 'response' },
      },
    },
  },
}

Add a way to inherit resolver into sub-flows

When specifying a flow with sub-flow(s), it is impossible to specify the resolvers in the parameter dynamically. So if the resolvers could be inherited from the outside flow it would be enough to solve this problem.

Can we support conditional branching?

I have a use case where I need to support conditional branching or invoking a resolver based on some condition. For example:-

resolverA() {
    api_call.then(()=>{
        //business logic
    }).catch(()=>{
        //invoke resolverB 
    })
}

When a task throws an error, the flow manager hangs.

Details on console

(node:5649) UnhandledPromiseRejectionWarning: #<Error>
(node:5649) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:5649) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Add object merge built-in task

Add a built-in task to merge objects.
Take into account precedence when fields are repeated in both objects.
Take into account merging more than 2 objects.

Param Pre-processing

Optional params pre-processing to make possible some simple processing without adding more tasks.
Examples of processing:

  • Extract a field from an object
  • Create an object from a value
  • Create a string from a value
  • Convert an object into another one

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.