kaxil commented on a change in pull request #5054: [AIRFLOW-4255] Replace 
Discovery based api with client based for GCS
URL: https://github.com/apache/airflow/pull/5054#discussion_r273009775
 
 

 ##########
 File path: airflow/contrib/hooks/gcs_hook.py
 ##########
 @@ -287,57 +236,41 @@ def is_updated_after(self, bucket, object, ts):
         :param ts: The timestamp to check against.
         :type ts: datetime.datetime
         """
-        service = self.get_conn()
-        try:
-            response = (service
-                        .objects()
-                        .get(bucket=bucket, object=object)
-                        .execute())
-
-            if 'updated' in response:
-                import dateutil.parser
-                import dateutil.tz
+        client = self.get_conn()
+        bucket = storage.Bucket(client=client, name=bucket)
+        blob = bucket.get_blob(blob_name=object)
+        blob.reload()
 
-                if not ts.tzinfo:
-                    ts = ts.replace(tzinfo=dateutil.tz.tzutc())
+        blob_update_time = blob.updated
 
-                updated = dateutil.parser.parse(response['updated'])
-                self.log.info("Verify object date: %s > %s", updated, ts)
+        if blob_update_time is not None:
+            import dateutil.tz
 
-                if updated > ts:
-                    return True
+            if not ts.tzinfo:
+                ts = ts.replace(tzinfo=dateutil.tz.tzutc())
 
-        except HttpError as ex:
-            if ex.resp['status'] != '404':
-                raise
+            self.log.info("Verify object date: %s > %s", blob_update_time, ts)
 
-        return False
+            if blob_update_time > ts:
+                return True
+            else:
+                return False
 
 Review comment:
   Good call.

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