You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "potiuk (via GitHub)" <gi...@apache.org> on 2023/02/21 08:18:03 UTC

[GitHub] [airflow] potiuk commented on a diff in pull request #28525: Add CloudRunExecuteJobOperator

potiuk commented on code in PR #28525:
URL: https://github.com/apache/airflow/pull/28525#discussion_r1112703777


##########
airflow/providers/google/cloud/hooks/cloud_run.py:
##########
@@ -0,0 +1,245 @@
+#
+# 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.
+"""This module contains a Google Cloud Run Hook."""
+from __future__ import annotations
+
+import json
+import time
+from typing import Any, Callable, Dict, List, Sequence, Union, cast
+
+from google.api_core.client_options import ClientOptions
+from googleapiclient.discovery import build
+
+from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
+from airflow.utils.log.logging_mixin import LoggingMixin
+
+DEFAULT_CLOUD_RUN_REGION = "us-central1"
+
+
+class CloudRunJobSteps:
+    """
+    Helper class with Cloud Run job status.
+    Reference: https://cloud.google.com/run/docs/reference/rest/v1/namespaces.jobs#JobStatus
+    """
+
+    EXEC_STEP_COMPLETED = "Completed"
+    EXEC_STEP_RESOURCES_AVAILABLE = "ResourcesAvailable"
+    EXEC_STEP_STARTED = "Started"
+    AWAITING_STEPS = {EXEC_STEP_STARTED, EXEC_STEP_RESOURCES_AVAILABLE}
+    ALL_STEPS = [EXEC_STEP_COMPLETED, EXEC_STEP_RESOURCES_AVAILABLE, EXEC_STEP_STARTED]
+
+
+class _CloudRunJobExecutionController(LoggingMixin):
+    """
+    Interface for communication with Google API.
+
+    :param cloud_run: Discovery resource
+    :param project_id: The Google Cloud Project ID.
+    :param execution_id: ID of a Cloud Run Job execution.
+    :param poll_sleep: The status refresh rate for pending operations.
+    :param num_retries: Maximum number of retries in case of connection problems.
+    :param wait_until_finished: If True, wait for the end of pipeline execution
+        before exiting. If False, it only submits job and check once if
+        the job is not in terminal state.
+    """
+
+    def __init__(
+        self,
+        cloud_run: Any,
+        project_id: str,
+        region: str,
+        wait_until_finished: bool,
+        execution_id: str | None = None,
+        poll_sleep: float = 10.0,
+        num_retries: int = 0,
+        job_exec_cold_start: float = 10.0,
+    ) -> None:
+
+        super().__init__()
+        self._cloud_run = cloud_run
+        self._project_id = project_id
+        self._region = region
+        self._exec_id = execution_id
+        self._poll_sleep = poll_sleep
+        self._num_retries = num_retries
+        self._execution: dict | None = None
+        self._execution_state: str | None = None
+        self._job_exec_cold_start = job_exec_cold_start
+        self._wait_until_finished = wait_until_finished
+
+    def _fetch_execution_by_id(self):
+        """
+        Helper method to fetch the execution with the specified execution ID.
+
+        :return: the Cloud Run job execution
+        """
+        self.log.debug("Fetching information for job execution %s", self._exec_id)
+        return (
+            self._cloud_run.namespaces()
+            .executions()
+            .get(name=f"namespaces/{self._project_id}/executions/{self._exec_id}")

Review Comment:
   This basically requires to upgrade all Google "properties" to the latest relesed versions of their clients. See for example https://github.com/apache/airflow/issues/27292 CC: @lwyszomi @bhirsz @VladaZakharova @mhenc @kosteev. I think there is no other way around it.
   
   We know what needs to be done, it just needs to be done :).
   



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org