-
Notifications
You must be signed in to change notification settings - Fork 38
Home
Swarvanu Sengupta edited this page Jul 14, 2019
·
9 revisions
faas-flow allows you to realize OpenFaaS function composition with ease. By defining a simple pipeline, you can orchestrate multiple functions without having to worry about internals.
import faasflow "github.com/s8sg/faas-flow"
func Define(flow *faasflow.Workflow, context *faasflow.Context) (err error) {
flow.Apply("Func1").Apply("Func2")
}
After building and deploying, it will give you a function that orchestrates calling Func2
with the output of Func1
By supplying a number of pipeline operators, complex composition can be achieved with little work:
The above pipeline can be achieved with little, but powerfull code:
SYNC-Chain
func Define(flow *faasflow.Workflow, context *faasflow.Context) (err error) {
flow.Apply("func1").Apply("func2").
Modify(func(data []byte) ([]byte, error) {
// Do something
return data, nil
})
return nil
}
AYNC-Chain
func Define(flow *faasflow.Workflow, context *faasflow.Context) (err error) {
dag := flow.Dag()
dag.AddFunction("n1", "func1")
dag.AddFunction("n2", "func2").
Modify(func(data []byte) ([]byte, error) {
// Do something
return data
}).
dag.Callback("n3","storage.io/bucket?id=3345612358265349126&file=result.dat")
dag.AddEdge("n1", "n2")
dag.AddEdge("n2", "n3")
flow.OnFailure(func(err error) {
// failure handler
}).
Finally(func(state string) {
// cleanup code
})
return nil
}
DAG-Call and Parallel
func Define(flow *faasflow.Workflow, context *faasflow.Context) (err error) {
dag := flow.Dag()
dag.AddModifier("n1", func(data []byte) ([]byte, error) {
// do something
return data, nil
})
dag.AddFunction("n2", "func1")
dag.AddFunction("n3", "func2").Modify("n4", func(data []byte) ([]byte, error) {
// do something
return data, nil
})
dag.AddCallback("n4", "storage.io/bucket?id=3345612358265349126&file=result")
dag.AddEdge("n1", "n2")
dag.AddEdge("n1", "n3")
dag.AddEdge("n2", "n4")
dag.AddEdge("n3", "n4")
return nil
}
Dynamic Branching
Check example dag: https://github.com/s8sg/branching-in-faas-flow