Skip to content

Commit

Permalink
网关支持流程级别自定义表达式和策略 (#184)
Browse files Browse the repository at this point in the history
* feature: 网关支持流程级别自定义表达式和策略

* minor: bamboo-engine version bumps to 2.9.0

* minor: bamboo-engine version bumps to 2.9.0
  • Loading branch information
normal-wls authored Oct 24, 2023
1 parent 684d0b2 commit de8379d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bamboo_engine/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
specific language governing permissions and limitations under the License.
"""

__version__ = "2.8.1"
__version__ = "2.9.0"
14 changes: 12 additions & 2 deletions bamboo_engine/eri/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
parent_pipeline_id: str,
can_skip: bool = True,
can_retry: bool = True,
name: str = None
name: str = None,
):
"""
Expand Down Expand Up @@ -164,6 +164,7 @@ def __init__(
conditions: List[Condition],
converge_gateway_id: str,
default_condition: DefaultCondition = None,
extra_info: dict = None,
*args,
**kwargs
):
Expand All @@ -178,14 +179,22 @@ def __init__(
self.conditions = conditions
self.default_condition = default_condition
self.converge_gateway_id = converge_gateway_id
self.extra_info = extra_info or {}


class ExclusiveGateway(Node):
"""
分支网关
"""

def __init__(self, conditions: List[Condition], default_condition: DefaultCondition = None, *args, **kwargs):
def __init__(
self,
conditions: List[Condition],
default_condition: DefaultCondition = None,
extra_info: dict = None,
*args,
**kwargs
):
"""
:param conditions: 分支条件
Expand All @@ -196,6 +205,7 @@ def __init__(self, conditions: List[Condition], default_condition: DefaultCondit
super().__init__(*args, **kwargs)
self.conditions = conditions
self.default_condition = default_condition
self.extra_info = extra_info or {}


class ServiceActivity(Node):
Expand Down
2 changes: 1 addition & 1 deletion bamboo_engine/handlers/conditional_parallel_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def execute(

try:
expr_func = self.runtime.get_config(RuntimeSettings.PIPELINE_EXCLUSIVE_GATEWAY_EXPR_FUNC.value)
result = expr_func(resolved_evaluate, hydrated_context)
result = expr_func(resolved_evaluate, hydrated_context, extra_info=self.node.extra_info)
logger.info(
"root_pipeline[%s] node(%s) %s test result: %s",
root_pipeline_id,
Expand Down
9 changes: 7 additions & 2 deletions bamboo_engine/handlers/exclusive_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def execute(
)
try:
expr_func = self.runtime.get_config(RuntimeSettings.PIPELINE_EXCLUSIVE_GATEWAY_EXPR_FUNC.value)
result = expr_func(resolved_evaluate, hydrated_context)
result = expr_func(resolved_evaluate, hydrated_context, extra_info=self.node.extra_info)
logger.info(
"root_pipeline[%s] node(%s) %s test result: %s",
root_pipeline_id,
Expand All @@ -124,7 +124,12 @@ def execute(
result,
)

strategy = self.runtime.get_config(RuntimeSettings.PIPELINE_EXCLUSIVE_GATEWAY_STRATEGY.value)
if isinstance(self.node.extra_info, dict) and self.node.extra_info.get("strategy") in [
s.name for s in ExclusiveGatewayStrategy
]:
strategy = self.node.extra_info["strategy"]
else:
strategy = self.runtime.get_config(RuntimeSettings.PIPELINE_EXCLUSIVE_GATEWAY_STRATEGY.value)
# 如果策略是命中第一个,并且result为true, 则直接结束循环
if strategy == ExclusiveGatewayStrategy.FIRST.value and result:
meet_conditions.append(c.name)
Expand Down
2 changes: 1 addition & 1 deletion bamboo_engine/utils/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
from bamboo_engine.utils.boolrule import BoolRule


def default_expr_func(expr: str, context: dict) -> bool:
def default_expr_func(expr: str, context: dict, extra_info: dict, *args, **kwargs) -> bool:
return BoolRule(expr).test()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bamboo-engine"
version = "2.8.1"
version = "2.9.0"
description = "Bamboo-engine is a general-purpose workflow engine"
authors = ["homholueng <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit de8379d

Please sign in to comment.