kis-flow/test/faas/faas_demo2.go

39 lines
988 B
Go
Raw Permalink Normal View History

2024-01-09 17:30:58 +08:00
package faas
import (
"context"
"fmt"
2024-04-16 15:11:23 +08:00
2024-03-26 14:54:50 +08:00
"github.com/aceld/kis-flow/kis"
"github.com/aceld/kis-flow/log"
2024-01-09 17:30:58 +08:00
)
// type FaaS func(context.Context, Flow) error
func FuncDemo2Handler(ctx context.Context, flow kis.Flow) error {
fmt.Println("---> Call funcName2Handler ----")
2024-01-26 17:27:29 +08:00
fmt.Printf("Params = %+v\n", flow.GetFuncParamAll())
2024-01-09 17:30:58 +08:00
for index, row := range flow.Input() {
2024-04-15 17:50:02 +08:00
str := fmt.Sprintf("In FuncName = %s, FuncId = %s, row = %s", flow.GetThisFuncConf().FName, flow.GetThisFunction().GetID(), row)
2024-01-09 17:30:58 +08:00
fmt.Println(str)
conn, err := flow.GetConnector()
if err != nil {
2024-04-15 11:17:47 +08:00
log.Logger().ErrorFX(ctx, "FuncDemo2Handler(): GetConnector err = %s\n", err.Error())
2024-01-09 17:30:58 +08:00
return err
}
if _, err := conn.Call(ctx, flow, row); err != nil {
2024-04-15 11:17:47 +08:00
log.Logger().ErrorFX(ctx, "FuncDemo2Handler(): Call err = %s\n", err.Error())
2024-01-09 17:30:58 +08:00
return err
}
resultStr := fmt.Sprintf("data from funcName[%s], index = %d", flow.GetThisFuncConf().FName, index)
_ = flow.CommitRow(resultStr)
}
return nil
}