bingqin2 commented on code in PR #72953:
URL: https://github.com/apache/airflow/pull/72953#discussion_r4146760328


##########
providers/google/src/airflow/providers/google/cloud/operators/gcs.py:
##########
@@ -996,7 +997,11 @@ def _download(blob_name: str):
                     )
                 destination_file.parent.mkdir(parents=True, exist_ok=True)
 
-                blob.download_to_filename(filename=str(destination_file))
+                self._run_with_attempts(
+                    lambda: 
blob.download_to_filename(filename=str(destination_file)),
+                    num_attempts=self.download_num_attempts,
+                    description=f"Download of 
gs://{self.source_bucket}/{blob_name}",
+                )

Review Comment:
   Done: `_download` is now decorated with `tenacity.retry`, with two 
differences from the snippet.
   
   - The stop uses the operator argument, 
`stop_after_attempt(self.download_num_attempts)`, which works because the 
function is defined inside `execute`.
   - It sets `reraise=True`. Without it, tenacity raises `RetryError` after the 
last attempt, and the `except GoogleCloudError` around `future.result()` (the 
`download_continue_on_fail` handling) would stop catching failures, even with 
the default of one attempt.
   
   Only `GoogleCloudError` is retried, so the path-containment `ValueError` 
still fails at once. `wait_exponential(multiplier=2, max=60)` keeps the 2, 4, 8 
s waits of `GCSHook.download`, and `before_sleep_log` logs each retry through 
the task logger.
   



##########
providers/google/src/airflow/providers/google/cloud/operators/gcs.py:
##########
@@ -1071,8 +1076,10 @@ def _upload(upload_file: Path):
 
                 blob = bucket.blob(blob_name=upload_file_name, 
chunk_size=self.chunk_size)
 
-                blob.upload_from_filename(
-                    filename=str(upload_file),
+                self._run_with_attempts(
+                    lambda: 
blob.upload_from_filename(filename=str(upload_file)),
+                    num_attempts=self.upload_num_attempts,
+                    description=f"Upload of {upload_file_name} to 
gs://{self.destination_bucket}",
                 )
 
                 return upload_file_name

Review Comment:
   Done, the same decorator on `_upload`, driven by `upload_num_attempts`.
   



##########
providers/google/src/airflow/providers/google/cloud/operators/gcs.py:
##########
@@ -1101,6 +1108,28 @@ def _upload(upload_file: Path):
 
             return files_uploaded
 
+    def _run_with_attempts(

Review Comment:
   Removed, together with the `time` and `Callable` imports it needed.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to