faas-flow icon indicating copy to clipboard operation
faas-flow copied to clipboard

Function output pipe into next function

Open heavenlxj opened this issue 2 years ago • 2 comments

i am confusing how to use the output in the function e.g. i have the 1st function like that:

def handle(req):
    """handle a request to the function
    Args:
        req (str): request body
    """
    print("This is the 1st Python API")
    return 1

and the 2nd function like this:

def handle(req):
    """handle a request to the function
    Args:
        req (str): request body
    """
    print("This is the Second Python API")
    print("Req is", req)
    a = int(req)
    b = a+1
    print("b is ",b)
    return b

Actually, i assume use the 1st function output in the 2nd function, if 1st ret 1, the 2nd will accept the output and make a is 1, then b=2 and return 2.

The flow code here:

func Define(flow *faasflow.Workflow, context *faasflow.Context) (err error) {
	flow.SyncNode().
		Apply("pytest1").
		Apply("pytest2").
		Modify(func(data []byte) ([]byte, error) {
			// do something
			fmt.Print(data)
			return data, nil
		})
	return nil
}

But when i invoke the flow function, it will throw the exception:

Internal Server Error [ Failed ] request failed to be processed. error: failed to execute request. Node(0_1_sync), Operation (pytest2), error: execution failed, Function(pytest2), error: function execution failed, invalid return status 500 while connecting http://gateway.openfaas:8080/function/pytest2

seems the 2nd function input req is None make the error. So what is the right way for this situation, for result pass? thanks for your help

may be the usage is wrong, i assume the intermediate date could store the output like context, so how to share the context between these functions?

or if i can set the context= { "result": "1st function output" }, then could use this context in the 2nd function, is it possible support?

heavenlxj avatar Apr 01 '22 16:04 heavenlxj

oh,I have the same question,do you solve this problem? can you teach me please?

TYsonHe avatar Aug 14 '23 02:08 TYsonHe

@s8sg

oh,I have the same question,do you solve this problem? can you teach me please?

TYsonHe avatar Aug 14 '23 07:08 TYsonHe