Skip to content

Commit a5292ea

Browse files
authored
hotfix: catch bucket job errors and increase backoff_factor for docdb (#133)
* hotfix: catch bucket job errors and increase backoff_factor for docdb * hotfix: lower page size for docdb * ci: version bump
1 parent f188ff1 commit a5292ea

File tree

5 files changed

+36
-5
lines changed

5 files changed

+36
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Package"""
22

3-
__version__ = "0.16.0"
3+
__version__ = "0.16.1"

src/aind_data_asset_indexer/aind_bucket_indexer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _create_docdb_client(self) -> MetadataDbClient:
8181
"""Create a MetadataDbClient with custom retries."""
8282
retry = Retry(
8383
total=3,
84-
backoff_factor=1,
84+
backoff_factor=10,
8585
status_forcelist=[429, 500, 502, 503, 504],
8686
allowed_methods=["GET", "POST", "DELETE"],
8787
)
@@ -761,7 +761,7 @@ def run_job(self):
761761
logging.info(f"Starting to scan through DocDb: {filter}")
762762
docdb_pages = paginate_docdb(
763763
docdb_api_client=iterator_docdb_client,
764-
page_size=500,
764+
page_size=200,
765765
filter_query=filter,
766766
)
767767
for page in docdb_pages:

src/aind_data_asset_indexer/codeocean_bucket_indexer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _create_docdb_client(self) -> MetadataDbClient:
5555
"""Create a MetadataDbClient with custom retries."""
5656
retry = Retry(
5757
total=3,
58-
backoff_factor=1,
58+
backoff_factor=10,
5959
status_forcelist=[429, 500, 502, 503, 504],
6060
allowed_methods=["GET", "POST", "DELETE"],
6161
)

src/aind_data_asset_indexer/index_aind_buckets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ def run_job(self):
3232
s3_bucket=bucket, **base_job_configs
3333
)
3434
bucket_job = AindIndexBucketJob(job_settings=bucket_job_settings)
35-
bucket_job.run_job()
35+
try:
36+
bucket_job.run_job()
37+
except Exception as e:
38+
logging.error(f"Error processing {bucket}. Error: {e}")
3639
logging.info(f"Finished processing {bucket}")
3740

3841

tests/test_index_aind_buckets.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ def test_run_job(self, mock_sub_run_job: MagicMock):
3636

3737
mock_sub_run_job.assert_has_calls([call(), call()])
3838

39+
@patch(
40+
"aind_data_asset_indexer.aind_bucket_indexer.AindIndexBucketJob."
41+
"run_job"
42+
)
43+
def test_run_job_error(self, mock_sub_run_job: MagicMock):
44+
"""Tests run_job method when there is an error in 1 bucket job."""
45+
46+
mock_sub_run_job.side_effect = [Exception("Some error"), None]
47+
job_settings = AindIndexBucketsJobSettings(
48+
s3_buckets=["bucket1", "bucket2"],
49+
doc_db_host="some_docdb_host",
50+
doc_db_db_name="some_docdb_dbname",
51+
doc_db_collection_name="some_docdb_collection_name",
52+
)
53+
job = IndexAindBucketsJob(job_settings=job_settings)
54+
with self.assertLogs(level="DEBUG") as captured:
55+
job.run_job()
56+
expected_log_messages = [
57+
"INFO:root:Processing bucket1",
58+
"ERROR:root:Error processing bucket1. Error: Some error",
59+
"INFO:root:Finished processing bucket1",
60+
"INFO:root:Processing bucket2",
61+
"INFO:root:Finished processing bucket2",
62+
]
63+
self.assertEqual(expected_log_messages, captured.output)
64+
65+
mock_sub_run_job.assert_has_calls([call(), call()])
66+
3967

4068
if __name__ == "__main__":
4169
unittest.main()

0 commit comments

Comments
 (0)