Light-Flow 任务编排框架 Light-Flow

Bilibotter • 1077 次点击    
这是一个分享于 的项目,其中的信息可能已经有所发展或是发生改变。
# LightFlow LightFlow是一个免编排的任务编排框架。 用户只需将注意力放在任务的执行时机上,而任务的编排由框架自动完成。 - **免编排**:专注于执行时机,使用函数式编程。 - **[可合并流程](https://github.com/Bilibotter/light-flow/blob/master/merge.cn.md)**:无缝地将已注册的流程合并到正在构建的流程中。 - **[多级回调](https://github.com/Bilibotter/light-flow/blob/master/callback.cn.md)**:各层级支持回调,灵活加入回调逻辑。 - **[多级配置](https://github.com/Bilibotter/light-flow/blob/master/config.cn.md)**:每个层级都可以设置配置,较小层级配置具有优先级。 - **[独特上下文机制](https://github.com/Bilibotter/light-flow/blob/master/context.cn.md)**:连接具有直接或间接依赖关系的步骤上下文,隔离没有依赖关系的步骤上下文。 - **尽最大可能执行**:即使某步骤失败,不依赖该步骤的其他步骤仍会继续执行。 ### 安装 `go get github.com/Bilibotter/light-flow` ### 使用 ```go import ( "fmt" flow "github.com/Bilibotter/light-flow" "strings" ) func Step1(ctx flow.StepCtx) (result interface{}, err error) { // Context can get value set by workflow input if input, exists := ctx.Get("flow-input"); exists { fmt.Printf("%s get workflow input, value = '%s'\n", ctx.ContextName(), input.(string)) } ctx.Set("step1-key", 1) result = "Step1 Result" return } func Step2(ctx flow.StepCtx) (result interface{}, err error) { if value, exists := ctx.Get("step1-key"); exists { fmt.Printf("%s get Step1 key, value = '%d'\n", ctx.ContextName(), value.(int)) } // Context can get related step's execute result by step name if step1Result, exists := ctx.GetResult("Step1"); exists { fmt.Printf("%s get Step1 result, value = `%s`\n", ctx.ContextName(), step1Result.(string)) } return } func AfterStepCallback(step *flow.Step) (keepOn bool, err error) { if step.Exceptions() != nil { fmt.Printf("%s executed faield %s occur\n", step.Name, strings.Join(step.Exceptions(), ",")) } return true, nil } func init() { workflow := flow.RegisterFlow("WorkFlow") process := workflow.Process("Process") process.Step(Step1) // Step2 depends on Step1 process.Step(Step2, Step1) // Use the callback function to handle errors during step execution workflow.AfterStep(false, AfterStepCallback) } func main() { // Complete the workflow with initial input values flow.DoneFlow("WorkFlow", map[string]interface{}{"flow-input": "Hello world!"}) } ```
授权协议:
MIT
开发语言:
Golang 查看源码»
1077 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传