RuleGo RuleGo
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • Quick Start

  • Rule Chain

  • Standard Components

  • Extension Components

  • Custom Components

  • Components marketplace

  • Visualization

  • AOP

  • Trigger

  • Advanced Topic

    • Config
    • Options
    • Share data
    • Execute Rule Chain
    • Component Configuration Variables
    • Component Connection Reuse
    • Performance
    • Other
    • RuleGo-Server

    • FAQ

    • Endpoint Module

    • Support

    目录

    Other

    # About Rule Engine Execution Interruption and Recovery

    There are scenarios where the rule engine execution instance needs to be interrupted and then resumed, such as:

    • Workflow Approval Scenario: In workflows that require manual approval, the execution of the rule engine may need to be paused until the necessary approval is obtained.
    • Third-Party System Asynchronous Callback: In scenarios that depend on the response of external systems, the rule engine may need to wait for the callback from the third-party system to continue execution.
    • Dependency Service Unavailable: When the execution of the rule engine depends on external services (such as databases, message queues, etc.), and these services are temporarily unavailable, the execution of the rule engine will be interrupted.

    The above requirements for the rule engine interruption and recovery scenario, without introducing a workflow, RuleGo is a good lightweight solution. RuleGo provides stateless interfaces, supporting the interruption and recovery of the rule engine execution, that is, when the rule engine execution is interrupted, it can be resumed to the state before the interruption.

    Here are the specific steps:

    1. Control the interruption of this execution instance through the execution context ctx.DoOnEnd, both the custom node message handling function and the custom function have this context.
    func OnMsg(ctx types.RuleContext, msg types.RuleMsg) {
        // Processing logic
        // Interrupt this execution instance, do not execute subsequent nodes, and notify the rule engine `OnEnd` callback function
        ctx.DoOnEnd(msg, err, relationType)
    }
    
    1
    2
    3
    4
    5
    1. Register the rule engine execution end callback function to persist msg and related state (if necessary): WithOnEnd.
    ruleEngine.OnMsg(msg, types.WithOnEnd(func(ctx types.RuleContext, msg types.RuleMsg, err error, relationType string) {
      // Persist the data of the current interrupted node
      // ctx.GetSelfId() The ID of the current node, used for recovery
      // msg.Id The ID of the message for this execution instance
      // msg.Data The data of the message for this execution instance
      // msg.Type The type of the message for this execution instance
      // msg.Metadata The metadata of the message for this execution instance
      // err.Error() The error information of this execution instance
      // relationType The relationship used to find the next node
    }))
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    1. Resume execution by providing the msg saved at the last interruption, the ID of the interrupted node, and specify the relationType to query the next node to resume execution.
    ruleEngine.OnMsg(msg, types.WithTellNext(fromNodeId string, relationTypes ...string))
    
    1
    Edit this page on GitHub (opens new window)
    Last Updated: 2025/04/02, 01:29:50
    Performance
    RuleGo-Server

    ← Performance RuleGo-Server→

    Theme by Vdoing | Copyright © 2023-2025 RuleGo Team | Apache 2.0 License

    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式