dazza-codes commented on a change in pull request #6811: [RFC][AIRFLOW-6245] 
Add custom waiters for AWS batch jobs
URL: https://github.com/apache/airflow/pull/6811#discussion_r361803289
 
 

 ##########
 File path: airflow/providers/amazon/aws/hooks/batch_client.py
 ##########
 @@ -0,0 +1,551 @@
+# -*- coding: utf-8 -*-
+#
+# 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.
+
+"""
+A client for AWS batch services
+
+.. seealso::
+
+    - http://boto3.readthedocs.io/en/latest/guide/configuration.html
+    - http://boto3.readthedocs.io/en/latest/reference/services/batch.html
+    - https://docs.aws.amazon.com/batch/latest/APIReference/Welcome.html
+"""
+
+from random import uniform
+from time import sleep
+from typing import Dict, List, Optional, Union
+
+import botocore.client
+import botocore.exceptions
+import botocore.waiter
+from typing_extensions import Protocol, runtime_checkable
+
+from airflow import AirflowException, LoggingMixin
+from airflow.contrib.hooks.aws_hook import AwsHook
+
+# pylint: disable=invalid-name, unused-argument
+
+
+@runtime_checkable
+class AwsBatchProtocol(Protocol):
+    """
+    A structured Protocol for ``boto3.client('batch') -> 
botocore.client.Batch``.
+    This is used for type hints on :py:meth:`.AwsBatchClient.client`; it covers
+    only the subset of client methods required.
+
+    .. seealso::
+
+        - https://mypy.readthedocs.io/en/latest/protocols.html
+        - http://boto3.readthedocs.io/en/latest/reference/services/batch.html
+    """
+
+    def describe_jobs(self, jobs: List[str]) -> Dict:
+        """
+        Get job descriptions from AWS batch
+
+        :param jobs: a list of JobId to describe
+        :type jobs: List[str]
+
+        :return: an API response to describe jobs
+        :rtype: Dict
+        """
+        ...
+
+    def get_waiter(self, waiterName: str) -> botocore.waiter.Waiter:
+        """
+        Get an AWS Batch service waiter
+
+        :param waiterName: The name of the waiter.  The name should match
+            the name (including the casing) of the key name in the waiter
+            model file (typically this is CamelCasing).
+        :type waiterName: str
+
+        :return: a waiter object for the named AWS batch service
+        :rtype: botocore.waiter.Waiter
+
+        .. note::
+            AWS batch might not have any waiters (until botocore PR-1307 is 
released).
+
+            .. code-block:: python
+
+                import boto3
+                boto3.client('batch').waiter_names == []
+
+        .. seealso::
+
+            - 
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/clients.html#waiters
+            - https://github.com/boto/botocore/pull/1307
+        """
+        ...
+
+    def submit_job(
+        self,
+        jobName: str,
+        jobQueue: str,
+        jobDefinition: str,
+        arrayProperties: Dict,
+        parameters: Dict,
+        containerOverrides: Dict,
+    ) -> Dict:
+        """
+        Submit a batch job
+
+        :param jobName: the name for the AWS batch job
+        :type jobName: str
+
+        :param jobQueue: the queue name on AWS Batch
+        :type jobQueue: str
+
+        :param jobDefinition: the job definition name on AWS Batch
+        :type jobDefinition: str
+
+        :param arrayProperties: the same parameter that boto3 will receive
+        :type arrayProperties: Dict
+
+        :param parameters: the same parameter that boto3 will receive
+        :type parameters: Dict
+
+        :param containerOverrides: the same parameter that boto3 will receive
+        :type containerOverrides: Dict
+
+        :return: an API response
+        :rtype: Dict
+        """
+        ...
+
+    def terminate_job(self, jobId: str, reason: str) -> Dict:
+        """
+        Terminate a batch job
+
+        :param jobId: a job ID to terminate
+        :type jobId: str
+
+        :param reason: a reason to terminate job ID
+        :type reason: str
+
+        :return: an API response
+        :rtype: Dict
+        """
+        ...
+
 
 Review comment:
   👍 and the `unused-argument` too; also adding comments about why this 
exception is added for the boto3 protocol.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to