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 06:57:39 UTC

[GitHub] [airflow] yeshbash opened a new pull request #19885: Add sensor for AWS Batch (#19850)

yeshbash opened a new pull request #19885:
URL: https://github.com/apache/airflow/pull/19885


   Adds a sensor implementation to ask for the status of an
   AWS Batch job. The sensor will enable DAGs to wait for the
   batch job to reach a terminal state before proceeding to the
   downstream tasks.
   
   Addresses: #19850
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/main/UPDATING.md).
   


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



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

Posted by GitBox <gi...@apache.org>.
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 otherwise and leaving the above two methods the same would be better.
   ```
   FAILURE_STATE = 'FAILED'
       SUCCESS_STATE = 'SUCCEEDED'
       RUNNING_STATE = 'RUNNING'
       INTERMEDIATE_STATES = (
           'SUBMITTED',
           'PENDING',
           'RUNNABLE',
           'STARTING',
           RUNNING_STATE,
       )
   ```




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



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

Posted by GitBox <gi...@apache.org>.
ferruzzi commented on a change in pull request #19885:
URL: https://github.com/apache/airflow/pull/19885#discussion_r759843444



##########
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',)
+
+    template_fields = ['job_id']
+    template_ext = ()
+    ui_color = '#66c3ff'
+
+    def __init__(
+        self,
+        *,
+        job_id: str,
+        aws_conn_id: str = 'aws_default',
+        region_name: Optional[str] = None,
+        **kwargs,
+    ):
+        super().__init__(**kwargs)
+        self.job_id = job_id
+        self.aws_conn_id = aws_conn_id
+        self.region_name = region_name
+        self.hook: Optional[AwsBatchClientHook] = None
+
+    def poke(self, context: Dict) -> bool:
+        job_description = self.get_hook().get_job_description(self.job_id)
+        state = job_description['status']
+
+        if state in self.FAILURE_STATES:
+            raise AirflowException(f'Batch sensor failed. Batch Job Status: {state}')
+
+        if state in self.INTERMEDIATE_STATES:
+            return False

Review comment:
       I appreciate the detailed reply; that makes sense.
   
   As an example of what I was thinking: the EKS Nodegroup sensor can be used to wait for the nodegroup to go "creating" so it can send the command to start spinning up a second, or wait to go "active" and trigger a task to run on it, or wait to go "nonexistent" so the cluster it is attached to could be deleted.   I was wondering if Batch had a usecase for adding similar logic, but it sounds like that may not be the case.  
   
   Carry on, and sorry for the distraction. πŸ˜„ 




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



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

Posted by GitBox <gi...@apache.org>.
yeshbash commented on a change in pull request #19885:
URL: https://github.com/apache/airflow/pull/19885#discussion_r759673198



##########
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',)
+
+    template_fields = ['job_id']
+    template_ext = ()
+    ui_color = '#66c3ff'
+
+    def __init__(
+        self,
+        *,
+        job_id: str,
+        aws_conn_id: str = 'aws_default',
+        region_name: Optional[str] = None,
+        **kwargs,
+    ):
+        super().__init__(**kwargs)
+        self.job_id = job_id
+        self.aws_conn_id = aws_conn_id
+        self.region_name = region_name
+        self.hook: Optional[AwsBatchClientHook] = None
+
+    def poke(self, context: Dict) -> bool:
+        job_description = self.get_hook().get_job_description(self.job_id)
+        state = job_description['status']
+
+        if state in self.FAILURE_STATES:
+            raise AirflowException(f'Batch sensor failed. Batch Job Status: {state}')
+
+        if state in self.INTERMEDIATE_STATES:
+            return False

Review comment:
       This sensor's objective is to poke until the job reaches a logical end - success/failure. In this context, I can't think of a use-case where matching against any other target state can be useful. There could be other places where we want to check against a target state and the AwsBatchClientHook already has a method for this.
   
   https://github.com/apache/airflow/blob/0df50f42dde4bd9b4c99cb6646416dde6fd4961e/airflow/providers/amazon/aws/hooks/batch_client.py#L321
   
   Let me know if I misunderstood your comment.




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



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

Posted by GitBox <gi...@apache.org>.
yeshbash commented on a change in pull request #19885:
URL: https://github.com/apache/airflow/pull/19885#discussion_r759750185



##########
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',)
+
+    template_fields = ['job_id']
+    template_ext = ()
+    ui_color = '#66c3ff'
+
+    def __init__(
+        self,
+        *,
+        job_id: str,
+        aws_conn_id: str = 'aws_default',
+        region_name: Optional[str] = None,
+        **kwargs,
+    ):
+        super().__init__(**kwargs)
+        self.job_id = job_id
+        self.aws_conn_id = aws_conn_id
+        self.region_name = region_name
+        self.hook: Optional[AwsBatchClientHook] = None
+
+    def poke(self, context: Dict) -> bool:
+        job_description = self.get_hook().get_job_description(self.job_id)
+        state = job_description['status']
+
+        if state in self.FAILURE_STATES:
+            raise AirflowException(f'Batch sensor failed. Batch Job Status: {state}')
+
+        if state in self.INTERMEDIATE_STATES:
+            return False

Review comment:
       I was looking at emr_sensor and that helped me understand your question better. Are you asking if making the terminal states configurable such that the sensor can return true/false based on it?
   
   I don't know a definitive answer but this is my thought process
   - I could see it useful for DAGs which follow a fire-and-forget pattern to launch the job.
   - In fire-and-forget scenarios, would there be a need to use a Sensor? - I don't think so
   - In the case of EMR, a cluster RUNNING could be a logical terminal state for long-running clusters. On the contrary, the batch is for ephemeral tasks and the same might not make sense
   - I see `AwsBatchOperator` providing this option through the `waiter` argument.
   
   With this, I'm inclining to say that a configurable terminal state might not be useful here. Let me know your thoughts
   




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



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

Posted by GitBox <gi...@apache.org>.
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



[GitHub] [airflow] github-actions[bot] commented on pull request #19885: Add sensor for AWS Batch (#19850)

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #19885:
URL: https://github.com/apache/airflow/pull/19885#issuecomment-986201350


   The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.


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



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

Posted by GitBox <gi...@apache.org>.
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 otherwise and 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



[GitHub] [airflow] boring-cyborg[bot] commented on pull request #19885: Add sensor for AWS Batch (#19850)

Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on pull request #19885:
URL: https://github.com/apache/airflow/pull/19885#issuecomment-986306924


   Awesome work, congrats on your first merged pull request!
   


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



[GitHub] [airflow] potiuk merged pull request #19885: Add sensor for AWS Batch (#19850)

Posted by GitBox <gi...@apache.org>.
potiuk merged pull request #19885:
URL: https://github.com/apache/airflow/pull/19885


   


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



[GitHub] [airflow] boring-cyborg[bot] commented on pull request #19885: Add sensor for AWS Batch (#19850)

Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on pull request #19885:
URL: https://github.com/apache/airflow/pull/19885#issuecomment-982339862


   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (flake8, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/STATIC_CODE_CHECKS.rst#prerequisites-for-pre-commit-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/BREEZE.rst) for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#coding-style-and-best-practices).
   Apache Airflow is a community-driven project and together we are making it better πŸš€.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


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



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

Posted by GitBox <gi...@apache.org>.
ferruzzi commented on a change in pull request #19885:
URL: https://github.com/apache/airflow/pull/19885#discussion_r759537771



##########
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',)
+
+    template_fields = ['job_id']
+    template_ext = ()
+    ui_color = '#66c3ff'
+
+    def __init__(
+        self,
+        *,
+        job_id: str,
+        aws_conn_id: str = 'aws_default',
+        region_name: Optional[str] = None,
+        **kwargs,
+    ):
+        super().__init__(**kwargs)
+        self.job_id = job_id
+        self.aws_conn_id = aws_conn_id
+        self.region_name = region_name
+        self.hook: Optional[AwsBatchClientHook] = None
+
+    def poke(self, context: Dict) -> bool:
+        job_description = self.get_hook().get_job_description(self.job_id)
+        state = job_description['status']
+
+        if state in self.FAILURE_STATES:
+            raise AirflowException(f'Batch sensor failed. Batch Job Status: {state}')
+
+        if state in self.INTERMEDIATE_STATES:
+            return False

Review comment:
       I'm not overly familiar with Batch yet.  Is there a use case for setting a target state?  Rather than just returning success/working/failed, is it desirable to have the option to check if it is currently RUNNING, for example?




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



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

Posted by GitBox <gi...@apache.org>.
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 otherwise and leaving the above two methods the same would be better.
   ```
       FAILURE_STATE = 'FAILED'
       SUCCESS_STATE = 'SUCCEEDED'
       RUNNING_STATE = 'RUNNING'
       INTERMEDIATE_STATES = (
           'SUBMITTED',
           'PENDING',
           'RUNNABLE',
           'STARTING',
           RUNNING_STATE,
       )
   ```




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



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

Posted by GitBox <gi...@apache.org>.
eladkal commented on a change in pull request #19885:
URL: https://github.com/apache/airflow/pull/19885#discussion_r759076711



##########
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:
       I think it would be better to manage the statuses on the hook level.
   The hook itself also has a function that require the same definitions:
   https://github.com/apache/airflow/blob/0df50f42dde4bd9b4c99cb6646416dde6fd4961e/airflow/providers/amazon/aws/hooks/batch_client.py#L248-L255
   
   So we should have one place to define it for both. 




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