Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/airflow/providers/microsoft/azure/sensors/cosmos.py: 0%
18 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
1#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18from __future__ import annotations
20from typing import TYPE_CHECKING, Sequence
22from airflow.providers.microsoft.azure.hooks.cosmos import AzureCosmosDBHook
23from airflow.sensors.base import BaseSensorOperator
25if TYPE_CHECKING:
26 from airflow.utils.context import Context
29class AzureCosmosDocumentSensor(BaseSensorOperator):
30 """
31 Checks for the existence of a document which matches the given query in CosmosDB.
33 .. code-block:: python
35 azure_cosmos_sensor = AzureCosmosDocumentSensor(
36 database_name="somedatabase_name",
37 collection_name="somecollection_name",
38 document_id="unique-doc-id",
39 azure_cosmos_conn_id="azure_cosmos_default",
40 task_id="azure_cosmos_sensor",
41 )
43 :param database_name: Target CosmosDB database_name.
44 :param collection_name: Target CosmosDB collection_name.
45 :param document_id: The ID of the target document.
46 :param azure_cosmos_conn_id: Reference to the
47 :ref:`Azure CosmosDB connection<howto/connection:azure_cosmos>`.
48 """
50 template_fields: Sequence[str] = ("database_name", "collection_name", "document_id")
52 def __init__(
53 self,
54 *,
55 database_name: str,
56 collection_name: str,
57 document_id: str,
58 azure_cosmos_conn_id: str = "azure_cosmos_default",
59 **kwargs,
60 ) -> None:
61 super().__init__(**kwargs)
62 self.azure_cosmos_conn_id = azure_cosmos_conn_id
63 self.database_name = database_name
64 self.collection_name = collection_name
65 self.document_id = document_id
67 def poke(self, context: Context) -> bool:
68 self.log.info("*** Entering poke")
69 hook = AzureCosmosDBHook(self.azure_cosmos_conn_id)
70 return hook.get_document(self.document_id, self.database_name, self.collection_name) is not None