Skip to content

Commit

Permalink
feature: 网关支持流程级别自定义表达式和策略
Browse files Browse the repository at this point in the history
  • Loading branch information
normal-wls committed Oct 23, 2023
1 parent 684d0b2 commit a919dba
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
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"]

Check warning on line 130 in bamboo_engine/handlers/exclusive_gateway.py

View check run for this annotation

Codecov / codecov/patch

bamboo_engine/handlers/exclusive_gateway.py#L130

Added line #L130 was not covered by tests
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()

0 comments on commit a919dba

Please sign in to comment.