ColtenOuO commented on code in PR #72133: URL: https://github.com/apache/airflow/pull/72133#discussion_r3869461080
########## providers/standard/docs/sensors/websocket.rst: ########## @@ -0,0 +1,43 @@ + .. 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. + + + +.. _howto/operator:WebSocketSensor: + +WebSocketSensor +================ + +Use the :class:`~airflow.providers.standard.sensors.websocket.WebSocketSensor` to wait for a message on a +``ws://`` or ``wss://`` WebSocket connection. This is useful when a remote server accepts a long-lived +connection and replies asynchronously once it has handled the requested work, since a plain HTTP request +is not well suited to that kind of long-lived connection. Requires the ``websocket`` extra +(``apache-airflow-providers-standard[websocket]``). + +.. exampleinclude:: /../src/airflow/providers/standard/example_dags/example_sensors.py + :language: python + :dedent: 4 + :start-after: [START example_websocket_sensor] + :end-before: [END example_websocket_sensor] + +Also for this job you can use sensor in the deferrable mode: + +.. exampleinclude:: /../src/airflow/providers/standard/example_dags/example_sensors.py + :language: python + :dedent: 4 + :start-after: [START example_websocket_sensor_async] + :end-before: [END example_websocket_sensor_async] Review Comment: Needs more samples ########## providers/standard/src/airflow/providers/standard/example_dags/example_sensors.py: ########## @@ -125,6 +126,22 @@ def failure_callable(): ) # [END example_day_of_week_sensor] + # [START example_websocket_sensor] + t12 = WebSocketSensor( + task_id="wait_for_websocket_message", url="wss://example.com/socket", timeout=3, soft_fail=True + ) + # [END example_websocket_sensor] + + # [START example_websocket_sensor_async] + t13 = WebSocketSensor( + task_id="wait_for_websocket_message_async", + url="wss://example.com/socket", + deferrable=True, + timeout=3, + soft_fail=True, + ) + # [END example_websocket_sensor_async] + Review Comment: Needs more samples -- 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]
