Merge pull request #18 from aceld/feature/aceld

change CaaS Function Type, add return value:interface{}
This commit is contained in:
刘丹冰 2024-04-03 13:44:02 +08:00 committed by GitHub
commit 5877e6fcda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 15 additions and 11 deletions

View File

@ -50,12 +50,16 @@ func (conn *KisConnector) Init() error {
} }
// Call 调用Connector 外挂存储逻辑的读写操作 // Call 调用Connector 外挂存储逻辑的读写操作
func (conn *KisConnector) Call(ctx context.Context, flow kis.Flow, args interface{}) error { func (conn *KisConnector) Call(ctx context.Context, flow kis.Flow, args interface{}) (interface{}, error) {
if err := kis.Pool().CallConnector(ctx, flow, conn, args); err != nil { var result interface{}
return err var err error
result, err = kis.Pool().CallConnector(ctx, flow, conn, args)
if err != nil {
return nil, err
} }
return nil return result, nil
} }
func (conn *KisConnector) GetName() string { func (conn *KisConnector) GetName() string {

View File

@ -9,7 +9,7 @@ type Connector interface {
// Init 初始化Connector所关联的存储引擎链接等 // Init 初始化Connector所关联的存储引擎链接等
Init() error Init() error
// Call 调用Connector 外挂存储逻辑的读写操作 // Call 调用Connector 外挂存储逻辑的读写操作
Call(ctx context.Context, flow Flow, args interface{}) error Call(ctx context.Context, flow Flow, args interface{}) (interface{}, error)
// GetId 获取Connector的ID // GetId 获取Connector的ID
GetId() string GetId() string
// GetName 获取Connector的名称 // GetName 获取Connector的名称

View File

@ -212,7 +212,7 @@ func (pool *kisPool) CaaS(cname string, fname string, mode common.KisMode, c Caa
} }
// CallConnector 调度 Connector // CallConnector 调度 Connector
func (pool *kisPool) CallConnector(ctx context.Context, flow Flow, conn Connector, args interface{}) error { func (pool *kisPool) CallConnector(ctx context.Context, flow Flow, conn Connector, args interface{}) (interface{}, error) {
pool.cLock.RLock() // 读锁 pool.cLock.RLock() // 读锁
defer pool.cLock.RUnlock() defer pool.cLock.RUnlock()
fn := flow.GetThisFunction() fn := flow.GetThisFunction()
@ -225,7 +225,7 @@ func (pool *kisPool) CallConnector(ctx context.Context, flow Flow, conn Connecto
log.Logger().ErrorFX(ctx, "CName:%s FName:%s mode:%s Can not find in KisPool, Not Added.\n", conn.GetName(), fnConf.FName, mode) log.Logger().ErrorFX(ctx, "CName:%s FName:%s mode:%s Can not find in KisPool, Not Added.\n", conn.GetName(), fnConf.FName, mode)
return errors.New(fmt.Sprintf("CName:%s FName:%s mode:%s Can not find in KisPool, Not Added.", conn.GetName(), fnConf.FName, mode)) return nil, errors.New(fmt.Sprintf("CName:%s FName:%s mode:%s Can not find in KisPool, Not Added.", conn.GetName(), fnConf.FName, mode))
} }
// GetFlows 得到全部的Flow // GetFlows 得到全部的Flow

View File

@ -34,7 +34,7 @@ type connInitRouter map[string]ConnInit
Connector Call Connector Call
*/ */
// CaaS Connector的存储读取业务实现 // CaaS Connector的存储读取业务实现
type CaaS func(context.Context, Connector, Function, Flow, interface{}) error type CaaS func(context.Context, Connector, Function, Flow, interface{}) (interface{}, error)
// connFuncRouter 通过FunctionName索引到CaaS回调存储业务的映射关系 // connFuncRouter 通过FunctionName索引到CaaS回调存储业务的映射关系
// key: Function Name // key: Function Name

View File

@ -8,7 +8,7 @@ import (
// type CaaS func(context.Context, Connector, Function, Flow, interface{}) error // type CaaS func(context.Context, Connector, Function, Flow, interface{}) error
func CaasDemoHanler1(ctx context.Context, conn kis.Connector, fn kis.Function, flow kis.Flow, args interface{}) error { func CaasDemoHanler1(ctx context.Context, conn kis.Connector, fn kis.Function, flow kis.Flow, args interface{}) (interface{}, error) {
fmt.Printf("===> In CaasDemoHanler1: flowName: %s, cName:%s, fnName:%s, mode:%s\n", fmt.Printf("===> In CaasDemoHanler1: flowName: %s, cName:%s, fnName:%s, mode:%s\n",
flow.GetName(), conn.GetName(), fn.GetConfig().FName, fn.GetConfig().FMode) flow.GetName(), conn.GetName(), fn.GetConfig().FName, fn.GetConfig().FMode)
@ -16,5 +16,5 @@ func CaasDemoHanler1(ctx context.Context, conn kis.Connector, fn kis.Function, f
fmt.Printf("===> Call Connector CaasDemoHanler1, args from funciton: %s\n", args) fmt.Printf("===> Call Connector CaasDemoHanler1, args from funciton: %s\n", args)
return nil return nil, nil
} }

View File

@ -23,7 +23,7 @@ func FuncDemo2Handler(ctx context.Context, flow kis.Flow) error {
return err return err
} }
if conn.Call(ctx, flow, row) != nil { if _, err := conn.Call(ctx, flow, row); err != nil {
log.Logger().ErrorFX(ctx, "FuncDemo2Handler(): Call err = %s\n", err.Error()) log.Logger().ErrorFX(ctx, "FuncDemo2Handler(): Call err = %s\n", err.Error())
return err return err
} }