Skip to content

Commit 7e09529

Browse files
matthew29tangcopybara-github
authored andcommitted
fix: Raise exception for RoV BQ Write for too many rate limit exceeded
PiperOrigin-RevId: 577271978
1 parent dc1b82a commit 7e09529

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

google/cloud/aiplatform/preview/vertex_ray/bigquery_datasource.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
gapic_version=_BQS_GAPIC_VERSION, user_agent=f"ray-on-vertex/{_BQS_GAPIC_VERSION}"
5151
)
5252

53+
MAX_RETRY_CNT = 20
54+
5355

5456
class _BigQueryDatasourceReader(Reader):
5557
def __init__(
@@ -192,7 +194,7 @@ def _write_single_block(
192194
pq.write_table(block, fp, compression="SNAPPY")
193195

194196
retry_cnt = 0
195-
while retry_cnt < 10:
197+
while retry_cnt < MAX_RETRY_CNT:
196198
with open(fp, "rb") as source_file:
197199
job = client.load_table_from_file(
198200
source_file, dataset, job_config=job_config
@@ -207,6 +209,14 @@ def _write_single_block(
207209
)
208210
logging.debug(e)
209211
time.sleep(11)
212+
213+
# Raise exception if retry_cnt hits MAX_RETRY_CNT
214+
if retry_cnt >= MAX_RETRY_CNT:
215+
raise RuntimeError(
216+
f"[Ray on Vertex AI]: Write failed due to {MAX_RETRY_CNT}"
217+
+ " repeated API rate limit exceeded responses"
218+
)
219+
210220
print("[Ray on Vertex AI]: Finished writing", metadata.num_rows, "rows")
211221

212222
project_id = project_id or initializer.global_config.project

0 commit comments

Comments
 (0)