feat: Add WORKFLOW_MAX_EXECUTION_TIME env var (#4632)

This commit is contained in:
majian 2024-05-24 15:27:12 +08:00 committed by GitHub
parent 3fda2245a4
commit 8c2ca60c8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 13 deletions

View File

@ -80,6 +80,8 @@ DEFAULTS = {
'INNER_API': 'False',
'ENTERPRISE_ENABLED': 'False',
'INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH': 1000,
'WORKFLOW_MAX_EXECUTION_STEPS': 50,
'WORKFLOW_MAX_EXECUTION_TIME': 600,
}
@ -385,3 +387,6 @@ class Config:
# Indexing Configurations.
# ------------------------
self.INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH = get_env('INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH')
self.WORKFLOW_MAX_EXECUTION_STEPS = get_env('WORKFLOW_MAX_EWORKFLOW_MAX_EXECUTION_STEPSXECUTION_STEPS')
self.WORKFLOW_MAX_EXECUTION_TIME = get_env('WORKFLOW_MAX_EXECUTION_TIME')

View File

@ -2,6 +2,8 @@ import logging
import time
from typing import Optional, cast
from flask import current_app
from core.app.app_config.entities import FileExtraConfig
from core.app.apps.base_app_queue_manager import GenerateTaskStoppedException
from core.file.file_obj import FileTransferMethod, FileType, FileVar
@ -128,6 +130,8 @@ class WorkflowEngineManager:
try:
predecessor_node = None
has_entry_node = False
max_execution_steps = current_app.config.get("WORKFLOW_MAX_EXECUTION_STEPS")
max_execution_time = current_app.config.get("WORKFLOW_MAX_EXECUTION_TIME")
while True:
# get next node, multiple target nodes in the future
next_node = self._get_next_node(
@ -148,13 +152,13 @@ class WorkflowEngineManager:
has_entry_node = True
# max steps 50 reached
if len(workflow_run_state.workflow_nodes_and_results) > 50:
raise ValueError('Max steps 50 reached.')
# max steps reached
if len(workflow_run_state.workflow_nodes_and_results) > max_execution_steps:
raise ValueError('Max steps {} reached.'.format(max_execution_steps))
# or max execution time 10min reached
if self._is_timed_out(start_at=workflow_run_state.start_at, max_execution_time=600):
raise ValueError('Max execution time 10min reached.')
# or max execution time reached
if self._is_timed_out(start_at=workflow_run_state.start_at, max_execution_time=max_execution_time):
raise ValueError('Max execution time {}s reached.'.format(max_execution_time))
# run workflow, run multiple target nodes in the future
self._run_workflow_node(