mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 12:37:20 +08:00
refactor(graph_engine): Convert attrs to private in error_handler
Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
parent
1cd0792606
commit
98b25c0bbc
@ -35,14 +35,14 @@ class ErrorHandler:
|
|||||||
graph: The workflow graph
|
graph: The workflow graph
|
||||||
graph_execution: The graph execution state
|
graph_execution: The graph execution state
|
||||||
"""
|
"""
|
||||||
self.graph = graph
|
self._graph = graph
|
||||||
self.graph_execution = graph_execution
|
self._graph_execution = graph_execution
|
||||||
|
|
||||||
# Initialize strategies
|
# Initialize strategies
|
||||||
self.abort_strategy = AbortStrategy()
|
self._abort_strategy = AbortStrategy()
|
||||||
self.retry_strategy = RetryStrategy()
|
self._retry_strategy = RetryStrategy()
|
||||||
self.fail_branch_strategy = FailBranchStrategy()
|
self._fail_branch_strategy = FailBranchStrategy()
|
||||||
self.default_value_strategy = DefaultValueStrategy()
|
self._default_value_strategy = DefaultValueStrategy()
|
||||||
|
|
||||||
def handle_node_failure(self, event: NodeRunFailedEvent) -> GraphNodeEventBase | None:
|
def handle_node_failure(self, event: NodeRunFailedEvent) -> GraphNodeEventBase | None:
|
||||||
"""
|
"""
|
||||||
@ -57,14 +57,14 @@ class ErrorHandler:
|
|||||||
Returns:
|
Returns:
|
||||||
Optional new event to process, or None to abort
|
Optional new event to process, or None to abort
|
||||||
"""
|
"""
|
||||||
node = self.graph.nodes[event.node_id]
|
node = self._graph.nodes[event.node_id]
|
||||||
# Get retry count from NodeExecution
|
# Get retry count from NodeExecution
|
||||||
node_execution = self.graph_execution.get_or_create_node_execution(event.node_id)
|
node_execution = self._graph_execution.get_or_create_node_execution(event.node_id)
|
||||||
retry_count = node_execution.retry_count
|
retry_count = node_execution.retry_count
|
||||||
|
|
||||||
# First check if retry is configured and not exhausted
|
# First check if retry is configured and not exhausted
|
||||||
if node.retry and retry_count < node.retry_config.max_retries:
|
if node.retry and retry_count < node.retry_config.max_retries:
|
||||||
result = self.retry_strategy.handle_error(event, self.graph, retry_count)
|
result = self._retry_strategy.handle_error(event, self._graph, retry_count)
|
||||||
if result:
|
if result:
|
||||||
# Retry count will be incremented when NodeRunRetryEvent is handled
|
# Retry count will be incremented when NodeRunRetryEvent is handled
|
||||||
return result
|
return result
|
||||||
@ -72,12 +72,10 @@ class ErrorHandler:
|
|||||||
# Apply configured error strategy
|
# Apply configured error strategy
|
||||||
strategy = node.error_strategy
|
strategy = node.error_strategy
|
||||||
|
|
||||||
if strategy is None:
|
match strategy:
|
||||||
return self.abort_strategy.handle_error(event, self.graph, retry_count)
|
case None:
|
||||||
elif strategy == ErrorStrategyEnum.FAIL_BRANCH:
|
return self._abort_strategy.handle_error(event, self._graph, retry_count)
|
||||||
return self.fail_branch_strategy.handle_error(event, self.graph, retry_count)
|
case ErrorStrategyEnum.FAIL_BRANCH:
|
||||||
elif strategy == ErrorStrategyEnum.DEFAULT_VALUE:
|
return self._fail_branch_strategy.handle_error(event, self._graph, retry_count)
|
||||||
return self.default_value_strategy.handle_error(event, self.graph, retry_count)
|
case ErrorStrategyEnum.DEFAULT_VALUE:
|
||||||
else:
|
return self._default_value_strategy.handle_error(event, self._graph, retry_count)
|
||||||
# Unknown strategy, default to abort
|
|
||||||
return self.abort_strategy.handle_error(event, self.graph, retry_count)
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user