fix: code

This commit is contained in:
Yeuoly 2024-03-17 21:08:25 +08:00
parent 73c2b35dfe
commit d8ab611480
No known key found for this signature in database
GPG Key ID: A66E7E320FB19F61
9 changed files with 24 additions and 7 deletions

View File

@ -97,6 +97,7 @@ class WorkflowEventTriggerCallback(BaseWorkflowCallback):
node_data: BaseNodeData,
error: str,
inputs: Optional[dict] = None,
outputs: Optional[dict] = None,
process_data: Optional[dict] = None) -> None:
"""
Workflow node execute failed
@ -107,6 +108,7 @@ class WorkflowEventTriggerCallback(BaseWorkflowCallback):
node_type=node_type,
node_data=node_data,
inputs=inputs,
outputs=outputs,
process_data=process_data,
error=error
),

View File

@ -96,6 +96,7 @@ class WorkflowEventTriggerCallback(BaseWorkflowCallback):
node_data: BaseNodeData,
error: str,
inputs: Optional[dict] = None,
outputs: Optional[dict] = None,
process_data: Optional[dict] = None) -> None:
"""
Workflow node execute failed
@ -106,6 +107,7 @@ class WorkflowEventTriggerCallback(BaseWorkflowCallback):
node_type=node_type,
node_data=node_data,
inputs=inputs,
outputs=outputs,
process_data=process_data,
error=error
),

View File

@ -168,6 +168,7 @@ class QueueNodeFailedEvent(AppQueueEvent):
node_data: BaseNodeData
inputs: Optional[dict] = None
outputs: Optional[dict] = None
process_data: Optional[dict] = None
error: str

View File

@ -218,7 +218,11 @@ class WorkflowCycleManage:
def _workflow_node_execution_failed(self, workflow_node_execution: WorkflowNodeExecution,
start_at: float,
error: str) -> WorkflowNodeExecution:
error: str,
inputs: Optional[dict] = None,
process_data: Optional[dict] = None,
outputs: Optional[dict] = None,
) -> WorkflowNodeExecution:
"""
Workflow node execution failed
:param workflow_node_execution: workflow node execution
@ -230,6 +234,9 @@ class WorkflowCycleManage:
workflow_node_execution.error = error
workflow_node_execution.elapsed_time = time.perf_counter() - start_at
workflow_node_execution.finished_at = datetime.utcnow()
workflow_node_execution.inputs = json.dumps(inputs) if inputs else None
workflow_node_execution.process_data = json.dumps(process_data) if process_data else None
workflow_node_execution.outputs = json.dumps(outputs) if outputs else None
db.session.commit()
db.session.refresh(workflow_node_execution)
@ -402,7 +409,10 @@ class WorkflowCycleManage:
workflow_node_execution = self._workflow_node_execution_failed(
workflow_node_execution=workflow_node_execution,
start_at=current_node_execution.start_at,
error=event.error
error=event.error,
inputs=event.inputs,
process_data=event.process_data,
outputs=event.outputs
)
db.session.close()

View File

@ -72,7 +72,7 @@ class CodeExecutor:
response = response.json()
except:
raise CodeExecutionException('Failed to parse response')
response = CodeExecutionResponse(**response)
if response.code != 0:

View File

@ -48,7 +48,7 @@ class PythonTemplateTransformer(TemplateTransformer):
:return:
"""
# extract result
result = re.search(r'<<RESULT>>(.*)<<RESULT>>', response, re.DOTALL)
result = re.search(r'<<RESULT>>(.*?)<<RESULT>>', response, re.DOTALL)
if not result:
raise ValueError('Failed to parse result')
result = result.group(1)

View File

@ -57,6 +57,7 @@ class BaseWorkflowCallback(ABC):
node_data: BaseNodeData,
error: str,
inputs: Optional[dict] = None,
outputs: Optional[dict] = None,
process_data: Optional[dict] = None) -> None:
"""
Workflow node execute failed

View File

@ -11,19 +11,19 @@ MAX_NUMBER = 2 ** 63 - 1
MIN_NUMBER = -2 ** 63
MAX_PRECISION = 20
MAX_DEPTH = 5
MAX_STRING_LENGTH = 1000
MAX_STRING_LENGTH = 5000
MAX_STRING_ARRAY_LENGTH = 30
MAX_NUMBER_ARRAY_LENGTH = 1000
JAVASCRIPT_DEFAULT_CODE = """function main({arg1, arg2}) {
return {
result: args1 + args2
result: arg1 + arg2
}
}"""
PYTHON_DEFAULT_CODE = """def main(arg1: int, arg2: int) -> dict:
return {
"result": args1 + args2,
"result": arg1 + arg2,
}"""
class CodeNode(BaseNode):

View File

@ -429,6 +429,7 @@ class WorkflowEngineManager:
node_data=node.node_data,
error=node_run_result.error,
inputs=node_run_result.inputs,
outputs=node_run_result.outputs,
process_data=node_run_result.process_data,
)