Re: [PR] Add AwaitMessageTrigger for Redis PubSub [airflow]

2025-07-18 Thread via GitHub


jason810496 commented on PR #52917:
URL: https://github.com/apache/airflow/pull/52917#issuecomment-3089519184

   > Looks good. Let me know when it's merged, I could take a crack at 
implementing a deferrable Redis pub sub sensor.
   
   Just merged!
   cc @seanghaeli 
   
   > I could take a crack at implementing a deferrable Redis pub sub sensor.
   
   Nice to hear that, thanks!


-- 
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]



Re: [PR] Add AwaitMessageTrigger for Redis PubSub [airflow]

2025-07-18 Thread via GitHub


jason810496 merged PR #52917:
URL: https://github.com/apache/airflow/pull/52917


-- 
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]



Re: [PR] Add AwaitMessageTrigger for Redis PubSub [airflow]

2025-07-14 Thread via GitHub


Programmer-RD-AI commented on code in PR #52917:
URL: https://github.com/apache/airflow/pull/52917#discussion_r2206097354


##
providers/redis/src/airflow/providers/redis/triggers/redis_await_message.py:
##
@@ -0,0 +1,72 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import asyncio
+from typing import Any
+
+from asgiref.sync import sync_to_async
+
+from airflow.providers.redis.hooks.redis import RedisHook
+from airflow.triggers.base import BaseTrigger, TriggerEvent
+
+
+class AwaitMessageTrigger(BaseTrigger):

Review Comment:
   got it, tnx 



-- 
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]



Re: [PR] Add AwaitMessageTrigger for Redis PubSub [airflow]

2025-07-14 Thread via GitHub


jason810496 commented on code in PR #52917:
URL: https://github.com/apache/airflow/pull/52917#discussion_r2204878443


##
providers/redis/src/airflow/providers/redis/triggers/redis_await_message.py:
##
@@ -0,0 +1,72 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import asyncio
+from typing import Any
+
+from asgiref.sync import sync_to_async
+
+from airflow.providers.redis.hooks.redis import RedisHook
+from airflow.triggers.base import BaseTrigger, TriggerEvent
+
+
+class AwaitMessageTrigger(BaseTrigger):

Review Comment:
   No strong option for the naming, having `Redis` in the naming works with me 
as well.
   Since using `AwaitMessageTrigger` as naming align the same usage in Apache 
Kafka provider.



-- 
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]



Re: [PR] Add AwaitMessageTrigger for Redis PubSub [airflow]

2025-07-13 Thread via GitHub


Programmer-RD-AI commented on code in PR #52917:
URL: https://github.com/apache/airflow/pull/52917#discussion_r2203408786


##
providers/redis/src/airflow/providers/redis/triggers/redis_await_message.py:
##
@@ -0,0 +1,72 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import asyncio
+from typing import Any
+
+from asgiref.sync import sync_to_async
+
+from airflow.providers.redis.hooks.redis import RedisHook
+from airflow.triggers.base import BaseTrigger, TriggerEvent
+
+
+class AwaitMessageTrigger(BaseTrigger):

Review Comment:
   would a name that includes Redis it self be a bit more clearer? just a 
thought



-- 
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]



Re: [PR] Add AwaitMessageTrigger for Redis PubSub [airflow]

2025-07-06 Thread via GitHub


Jasperora commented on PR #52917:
URL: https://github.com/apache/airflow/pull/52917#issuecomment-3041728575

   Sure! I've added the documentation for the trigger.


-- 
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]



Re: [PR] Add AwaitMessageTrigger for Redis PubSub [airflow]

2025-07-06 Thread via GitHub


Jasperora commented on code in PR #52917:
URL: https://github.com/apache/airflow/pull/52917#discussion_r2188326691


##
providers/redis/src/airflow/providers/redis/triggers/redis_await_message.py:
##
@@ -0,0 +1,69 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import asyncio
+from typing import Any
+
+from airflow.providers.redis.hooks.redis import RedisHook
+from airflow.triggers.base import BaseTrigger, TriggerEvent
+
+
+class AwaitMessageTrigger(BaseTrigger):
+"""
+A trigger that waits for a message matching specific criteria to arrive in 
Redis.
+
+The behavior of this trigger is as follows:
+- poll the Redis pubsub for a message, if no message returned, sleep
+
+:param channels: The channels that should be searched for messages
+:param redis_conn_id: The connection object to use, defaults to 
"redis_default"
+:param poll_interval: How long the trigger should sleep after reaching the 
end of the Redis log
+(seconds), defaults to 60
+"""
+
+def __init__(
+self,
+channels: list[str] | str,
+redis_conn_id: str = "redis_default",
+poll_interval: float = 60,
+) -> None:
+self.channels = channels
+self.redis_conn_id = redis_conn_id
+self.poll_interval = poll_interval
+
+def serialize(self) -> tuple[str, dict[str, Any]]:
+return (
+
"airflow.providers.redis.triggers.redis_await_message.AwaitMessageTrigger",
+{
+"channels": self.channels,
+"redis_conn_id": self.redis_conn_id,
+"poll_interval": self.poll_interval,
+},
+)
+
+async def run(self):
+hook = RedisHook(redis_conn_id=self.redis_conn_id).get_conn().pubsub()
+hook.subscribe(self.channels)
+
+while True:
+message = hook.get_message()

Review Comment:
   Thanks for reminding and guidance. I've added it at the commit [add 
sync_to_async](https://github.com/apache/airflow/pull/52917/commits/8eacb2ab38281e5906f91fb3e72fb163a56ae5c8).



-- 
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]



Re: [PR] Add AwaitMessageTrigger for Redis PubSub [airflow]

2025-07-06 Thread via GitHub


jason810496 commented on code in PR #52917:
URL: https://github.com/apache/airflow/pull/52917#discussion_r2188081556


##
providers/redis/src/airflow/providers/redis/triggers/redis_await_message.py:
##
@@ -0,0 +1,69 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import asyncio
+from typing import Any
+
+from airflow.providers.redis.hooks.redis import RedisHook
+from airflow.triggers.base import BaseTrigger, TriggerEvent
+
+
+class AwaitMessageTrigger(BaseTrigger):
+"""
+A trigger that waits for a message matching specific criteria to arrive in 
Redis.
+
+The behavior of this trigger is as follows:
+- poll the Redis pubsub for a message, if no message returned, sleep
+
+:param channels: The channels that should be searched for messages
+:param redis_conn_id: The connection object to use, defaults to 
"redis_default"
+:param poll_interval: How long the trigger should sleep after reaching the 
end of the Redis log
+(seconds), defaults to 60
+"""
+
+def __init__(
+self,
+channels: list[str] | str,
+redis_conn_id: str = "redis_default",
+poll_interval: float = 60,
+) -> None:
+self.channels = channels
+self.redis_conn_id = redis_conn_id
+self.poll_interval = poll_interval
+
+def serialize(self) -> tuple[str, dict[str, Any]]:
+return (
+
"airflow.providers.redis.triggers.redis_await_message.AwaitMessageTrigger",
+{
+"channels": self.channels,
+"redis_conn_id": self.redis_conn_id,
+"poll_interval": self.poll_interval,
+},
+)
+
+async def run(self):
+hook = RedisHook(redis_conn_id=self.redis_conn_id).get_conn().pubsub()
+hook.subscribe(self.channels)
+
+while True:
+message = hook.get_message()

Review Comment:
   I think we need  `sync_to_async` to avoid blocking call in asyncio.
   

For example: 
https://github.com/apache/airflow/blob/main/providers/apache/kafka/src/airflow/providers/apache/kafka/triggers/await_message.py#L94-L102



-- 
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]