Skip to content

Commit 3146c9c

Browse files
authored
chore: added increased timeout on flaky batch request (#84)
1 parent 9dd0c67 commit 3146c9c

4 files changed

+6
-4
lines changed

documentai/snippets/batch_parse_form_v1beta2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def batch_parse_form(
2424
project_id="YOUR_PROJECT_ID",
2525
input_uri="gs://cloud-samples-data/documentai/form.pdf",
2626
destination_uri="gs://your-bucket-id/path/to/save/results/",
27+
timeout=90
2728
):
2829
"""Parse a form"""
2930

@@ -80,7 +81,7 @@ def batch_parse_form(
8081
operation = client.batch_process_documents(batch_request)
8182

8283
# Wait for the operation to finish
83-
operation.result()
84+
operation.result(timeout)
8485

8586
# Results are written to GCS. Use a regex to find
8687
# output files

documentai/snippets/batch_parse_form_v1beta2_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ def setup_teardown():
4141

4242

4343
def test_batch_parse_form(capsys):
44-
batch_parse_form_v1beta2.batch_parse_form(PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI)
44+
batch_parse_form_v1beta2.batch_parse_form(PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI, 120)
4545
out, _ = capsys.readouterr()
4646
assert "Output files" in out

documentai/snippets/batch_parse_table_v1beta2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def batch_parse_table(
2424
project_id="YOUR_PROJECT_ID",
2525
input_uri="gs://cloud-samples-data/documentai/form.pdf",
2626
destination_uri="gs://your-bucket-id/path/to/save/results/",
27+
timeout=90
2728
):
2829
"""Parse a form"""
2930

@@ -88,7 +89,7 @@ def batch_parse_table(
8889
operation = client.batch_process_documents(batch_request)
8990

9091
# Wait for the operation to finish
91-
operation.result()
92+
operation.result(timeout)
9293

9394
# Results are written to GCS. Use a regex to find
9495
# output files

documentai/snippets/batch_parse_table_v1beta2_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ def setup_teardown():
4141

4242

4343
def test_batch_parse_table(capsys):
44-
batch_parse_table_v1beta2.batch_parse_table(PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI)
44+
batch_parse_table_v1beta2.batch_parse_table(PROJECT_ID, INPUT_URI, BATCH_OUTPUT_URI, 120)
4545
out, _ = capsys.readouterr()
4646
assert "Output files:" in out

0 commit comments

Comments
 (0)