Lee-W commented on code in PR #66584:
URL: https://github.com/apache/airflow/pull/66584#discussion_r3292223126
##########
airflow-core/src/airflow/triggers/base.py:
##########
@@ -269,6 +313,80 @@ def hash(classpath: str, kwargs: dict[str, Any]) -> int:
normalized = encode_trigger({"classpath": classpath, "kwargs":
kwargs})["kwargs"]
return hash((classpath,
json.dumps(BaseSerialization.serialize(normalized)).encode("utf-8")))
+ def shared_stream_key(self) -> Hashable | None:
+ """
+ Identify an underlying I/O stream that can be shared with sibling
triggers.
+
+ Two trigger instances whose ``shared_stream_key()`` return values
+ compare equal (and are not ``None``) will share a single underlying
+ poll loop in the triggerer. Each instance still receives the events
+ it cares about through its own :meth:`filter_shared_stream` call.
+
+ Returning ``None`` (the default) opts out of sharing — the trigger
+ runs its own independent poll loop via :meth:`run`, exactly as today.
+
+ The return value is read **once** when ``run_trigger`` first starts
+ this trigger; any change to the key afterwards has no effect on
+ group membership for this instance. To share one poll across a set
+ of sibling triggers, ensure every trigger in the set returns the
+ same key from the outset.
+
+ .. note::
+
+ This method is called **after** :meth:`render_template_fields`,
+ so any templated attribute (for example a ``directory`` derived
+ from a Jinja expression) is already resolved when the key is
+ constructed. Two sibling triggers that render to the same path
+ will correctly share their poll.
+ """
+ return None
+
+ @classmethod
+ async def open_shared_stream(cls, kwargs: dict[str, Any]) ->
AsyncIterator[Any]:
Review Comment:
The raw stream is a private contract between `open_shared_stream` and
`filter_shared_stream` — `T` never crosses an API boundary, so the TypeVar
would serve only as documentation for the subclass author.
I'd rather skip it unless users ask for it, which I doubt anyone would ever
do.
--
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]