perf: Skip browser logging for production tasks in native Python runner (#19028)

This commit is contained in:
Iván Ovejero
2025-09-01 10:55:20 +02:00
committed by GitHub
parent 864b51d135
commit d0ffd6e659
5 changed files with 25 additions and 3 deletions

View File

@@ -50,6 +50,7 @@ def _parse_task_settings(d: dict) -> BrokerTaskSettings:
workflow_id = settings_dict.get("workflowId", "Unknown") workflow_id = settings_dict.get("workflowId", "Unknown")
node_name = settings_dict.get("nodeName", "Unknown") node_name = settings_dict.get("nodeName", "Unknown")
node_id = settings_dict.get("nodeId", "Unknown") node_id = settings_dict.get("nodeId", "Unknown")
can_log = settings_dict.get("canLog", False)
except KeyError as e: except KeyError as e:
raise ValueError(f"Missing field in task settings message: {e}") raise ValueError(f"Missing field in task settings message: {e}")
@@ -64,6 +65,7 @@ def _parse_task_settings(d: dict) -> BrokerTaskSettings:
workflow_id=workflow_id, workflow_id=workflow_id,
node_name=node_name, node_name=node_name,
node_id=node_id, node_id=node_id,
can_log=can_log,
), ),
) )

View File

@@ -43,6 +43,7 @@ class TaskSettings:
workflow_id: str workflow_id: str
node_name: str node_name: str
node_id: str node_id: str
can_log: bool
@dataclass @dataclass

View File

@@ -35,6 +35,7 @@ class TaskExecutor:
stdlib_allow: Set[str], stdlib_allow: Set[str],
external_allow: Set[str], external_allow: Set[str],
builtins_deny: set[str], builtins_deny: set[str],
can_log: bool,
): ):
"""Create a subprocess for executing a Python code task and a queue for communication.""" """Create a subprocess for executing a Python code task and a queue for communication."""
@@ -47,7 +48,15 @@ class TaskExecutor:
queue = MULTIPROCESSING_CONTEXT.Queue() queue = MULTIPROCESSING_CONTEXT.Queue()
process = MULTIPROCESSING_CONTEXT.Process( process = MULTIPROCESSING_CONTEXT.Process(
target=fn, target=fn,
args=(code, items, queue, stdlib_allow, external_allow, builtins_deny), args=(
code,
items,
queue,
stdlib_allow,
external_allow,
builtins_deny,
can_log,
),
) )
return process, queue return process, queue
@@ -114,6 +123,7 @@ class TaskExecutor:
stdlib_allow: Set[str], stdlib_allow: Set[str],
external_allow: Set[str], external_allow: Set[str],
builtins_deny: set[str], builtins_deny: set[str],
can_log: bool,
): ):
"""Execute a Python code task in all-items mode.""" """Execute a Python code task in all-items mode."""
@@ -129,7 +139,9 @@ class TaskExecutor:
globals = { globals = {
"__builtins__": TaskExecutor._filter_builtins(builtins_deny), "__builtins__": TaskExecutor._filter_builtins(builtins_deny),
"_items": items, "_items": items,
"print": TaskExecutor._create_custom_print(print_args), "print": TaskExecutor._create_custom_print(print_args)
if can_log
else print,
} }
exec(code, globals) exec(code, globals)
@@ -149,6 +161,7 @@ class TaskExecutor:
stdlib_allow: Set[str], stdlib_allow: Set[str],
external_allow: Set[str], external_allow: Set[str],
builtins_deny: set[str], builtins_deny: set[str],
can_log: bool,
): ):
"""Execute a Python code task in per-item mode.""" """Execute a Python code task in per-item mode."""
@@ -167,7 +180,9 @@ class TaskExecutor:
globals = { globals = {
"__builtins__": TaskExecutor._filter_builtins(builtins_deny), "__builtins__": TaskExecutor._filter_builtins(builtins_deny),
"_item": item, "_item": item,
"print": TaskExecutor._create_custom_print(print_args), "print": TaskExecutor._create_custom_print(print_args)
if can_log
else print,
} }
exec(compiled_code, globals) exec(compiled_code, globals)

View File

@@ -237,6 +237,7 @@ class TaskRunner:
stdlib_allow=self.opts.stdlib_allow, stdlib_allow=self.opts.stdlib_allow,
external_allow=self.opts.external_allow, external_allow=self.opts.external_allow,
builtins_deny=self.opts.builtins_deny, builtins_deny=self.opts.builtins_deny,
can_log=task_settings.can_log,
) )
task_state.process = process task_state.process = process

View File

@@ -38,6 +38,9 @@ export class PythonTaskRunnerSandbox {
nodeName: node.name, nodeName: node.name,
workflowId: workflow.id, workflowId: workflow.id,
workflowName: workflow.name, workflowName: workflow.name,
/** Whether this task can log to the browser console. */
canLog: this.executeFunctions.getMode() === 'manual',
}; };
const executionResult = await this.executeFunctions.startJob<INodeExecutionData[]>( const executionResult = await this.executeFunctions.startJob<INodeExecutionData[]>(