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 2020/04/02 11:17:19 UTC

[GitHub] [airflow] abdulbasitds commented on a change in pull request #6007: [AIRFLOW-2310] Enable AWS Glue Job Integration

abdulbasitds commented on a change in pull request #6007: [AIRFLOW-2310] Enable AWS Glue Job Integration
URL: https://github.com/apache/airflow/pull/6007#discussion_r402236060
 
 

 ##########
 File path: airflow/providers/amazon/aws/sensors/glue.py
 ##########
 @@ -0,0 +1,57 @@
+# -*- 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.
+
+from airflow.sensors.base_sensor_operator import BaseSensorOperator
+from airflow.utils.decorators import apply_defaults
+from airflow.providers.amazon.aws.hooks.glue import AwsGlueJobHook
+
+
+class AwsGlueJobSensor(BaseSensorOperator):
+    """
+    Waits for an AWS Glue Job to reach any of the status below
+    'FAILED', 'STOPPED', 'SUCCEEDED'
+
+    :param job_name: The AWS Glue Job unique name
+    :type str
+    :param run_id: The AWS Glue current running job identifier
+    :type str
+    """
+    template_fields = ('job_name', 'run_id')
+
+    @apply_defaults
+    def __init__(self,
+                 job_name,
+                 run_id,
+                 aws_conn_id='aws_default',
+                 *args,
+                 **kwargs):
+        super(AwsGlueJobSensor, self).__init__(*args, **kwargs)
+        self.job_name = job_name
+        self.run_id = run_id
+        self.aws_conn_id = aws_conn_id
+        self.targeted_status = ['FAILED', 'STOPPED', 'SUCCEEDED']
+
+    def poke(self, context):
+        self.log.info("Poking for job run status : {self.targeted_status}\n"
+                      "for Glue Job {self.job_name} and ID {self.run_id}"
+                      .format(**locals()))
+        hook = AwsGlueJobHook(aws_conn_id=self.aws_conn_id)
+        job_state = hook.job_completion(job_name=self.job_name,
+                                        run_id=self.run_id)
+        return job_state['JobRunState'].upper() in self.targeted_status
 
 Review comment:
   Yes, Actually I wasn't using it before but there were inconsistency in either of the status which was coming back as lower, I don#t remember which one was it.
   
   Should i mark it resolved?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services