🔥A cross-language distributed transaction manager. Support xa, tcc, saga, transactional messages. 跨语言分布式事务管理器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

46 lines
1.0 KiB

package workflow
import (
"context"
"fmt"
"github.com/dtm-labs/logger"
)
type workflowFactory struct {
protocol string
httpDtm string
httpCallback string
grpcDtm string
grpcCallback string
handlers map[string]*wfItem
}
var defaultFac = workflowFactory{
handlers: map[string]*wfItem{},
}
func (w *workflowFactory) execute(ctx context.Context, name string, gid string, data []byte) ([]byte, error) {
handler := w.handlers[name]
if handler == nil {
return nil, fmt.Errorf("workflow '%s' not registered. please register at startup", name)
}
wf := w.newWorkflow(ctx, name, gid, data)
for _, fn := range handler.custom {
fn(wf)
}
return wf.process(handler.fn, data)
}
func (w *workflowFactory) register(name string, handler WfFunc2, custom ...func(wf *Workflow)) error {
e := w.handlers[name]
if e != nil {
return fmt.Errorf("a handler already exists for %s", name)
}
logger.Debugf("workflow '%s' registered.", name)
w.handlers[name] = &wfItem{
fn: handler,
custom: custom,
}
return nil
}