jscheffl commented on code in PR #59876:
URL: https://github.com/apache/airflow/pull/59876#discussion_r2679448780
##########
task-sdk/src/airflow/sdk/execution_time/task_runner.py:
##########
@@ -736,17 +734,52 @@ def parse(what: StartupDetails, log: Logger) ->
RuntimeTaskInstance:
)
-# This global variable will be used by Connection/Variable/XCom classes, or
other parts of the task's execution,
+# This global class will be used by Connection/Variable/XCom classes, or other
parts of the task's execution,
# to send requests back to the supervisor process.
#
# Why it needs to be a global:
# - Many parts of Airflow's codebase (e.g., connections, variables, and XComs)
may rely on making dynamic requests
# to the parent process during task execution.
# - These calls occur in various locations and cannot easily pass the
`CommsDecoder` instance through the
# deeply nested execution stack.
-# - By defining `SUPERVISOR_COMMS` as a global, it ensures that this
communication mechanism is readily
+# - By defining this as a static class with accessors, it ensures that this
communication mechanism is readily
# accessible wherever needed during task execution without modifying every
layer of the call stack.
-SUPERVISOR_COMMS: CommsDecoder[ToTask, ToSupervisor]
+# Not perfect but getter than a global variable.
+class _SupervisorCommsHolder:
+ comms: CommsDecoder[ToTask, ToSupervisor] | None = None
+
+
+def supervisor_send(msg: ToSupervisor) -> ToTask | None:
+ """Send a message to the supervisor as convenience for
get_supervisor_comms().send()."""
+ if _SupervisorCommsHolder.comms is None:
+ raise RuntimeError("Supervisor comms not initialized yet. Call
set_supervisor_comms() instead.")
+ return _SupervisorCommsHolder.comms.send(msg)
Review Comment:
I have reworked the `SupervisorComms` now to be a Singleton.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]