You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/11/30 14:56:00 UTC

[GitHub] [airflow] yeshbash commented on a change in pull request #19885: Add sensor for AWS Batch (#19850)

yeshbash commented on a change in pull request #19885:
URL: https://github.com/apache/airflow/pull/19885#discussion_r759359679



##########
File path: airflow/providers/amazon/aws/sensors/batch.py
##########
@@ -0,0 +1,85 @@
+# 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 typing import Dict, Optional
+
+from airflow.exceptions import AirflowException
+from airflow.providers.amazon.aws.hooks.batch_client import AwsBatchClientHook
+from airflow.sensors.base import BaseSensorOperator
+
+
+class BatchSensor(BaseSensorOperator):
+    """
+    Asks for the state of the Batch Job execution until it reaches a failure state or success state.
+    If the job fails, the task will fail.
+
+    :param job_id: Batch job_id to check the state for
+    :type job_id: str
+    :param aws_conn_id: aws connection to use, defaults to 'aws_default'
+    :type aws_conn_id: str
+    """
+
+    INTERMEDIATE_STATES = (
+        'SUBMITTED',
+        'PENDING',
+        'RUNNABLE',
+        'STARTING',
+        'RUNNING',
+    )
+    FAILURE_STATES = ('FAILED',)
+    SUCCESS_STATES = ('SUCCEEDED',)

Review comment:
       Good point - I will define these in `AwsBatchClientHook` and reference it.
   
   While making the change, I noticed that the hook also uses two additional combinations of state values for its own methods
   
   1. `poll_for_job_running`: checks for `["RUNNING", "SUCCEEDED", "FAILED"]`.
   2. `poll_for_job_complete` : checks for `["SUCCEEDED", "FAILED"]`
   
   I'm planning to create the following state definitions to cater to all cases. Let me know if you think leaving the above two methods the same would be better.
   ```
       TRANSIENT_STATES = (
           'SUBMITTED',
           'PENDING',
           'RUNNABLE',
           'STARTING',
       )
       FAILURE_STATE = 'FAILED'
       SUCCESS_STATE = 'SUCCEEDED'
       RUNNING_STATE = 'RUNNING'
   ```




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