Skip to content

Commit c56cfa5

Browse files
authored
Improve DCS cleanup job error messages (#117)
1 parent f60553d commit c56cfa5

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

services/dcs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ We recommend using the provided Docker container.
4343

4444
A pre-built version is available at [docker hub](https://hub.docker.com/repository/docker/ghga/download-controller-service):
4545
```bash
46-
docker pull ghga/download-controller-service:6.1.1
46+
docker pull ghga/download-controller-service:6.1.2
4747
```
4848

4949
Or you can build the container yourself from the [`./Dockerfile`](./Dockerfile):
5050
```bash
5151
# Execute in the repo's root dir:
52-
docker build -t ghga/download-controller-service:6.1.1 .
52+
docker build -t ghga/download-controller-service:6.1.2 .
5353
```
5454

5555
For production-ready deployment, we recommend using Kubernetes, however,
5656
for simple use cases, you could execute the service using docker
5757
on a single server:
5858
```bash
5959
# The entrypoint is preconfigured:
60-
docker run -p 8080:8080 ghga/download-controller-service:6.1.1 --help
60+
docker run -p 8080:8080 ghga/download-controller-service:6.1.2 --help
6161
```
6262

6363
If you prefer not to use containers, you may install the service from source:

services/dcs/openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ info:
206206
\ Object Storage. \n\nThis is an implementation of the DRS standard from the Global\
207207
\ Alliance for Genomics and Health, please find more information at: https://github.com/ga4gh/data-repository-service-schemas"
208208
title: Download Controller Service
209-
version: 6.1.1
209+
version: 6.1.2
210210
openapi: 3.1.0
211211
paths:
212212
/health:

services/dcs/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ classifiers = [
2121
"Intended Audience :: Developers",
2222
]
2323
name = "dcs"
24-
version = "6.1.1"
24+
version = "6.1.2"
2525
description = "Download Controller Service - a GA4GH DRS-compliant service for delivering files from S3 encrypted according to the GA4GH Crypt4GH standard."
2626

2727

services/dcs/src/dcs/core/data_repository.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ async def access_drs_object(self, *, drs_id: str) -> models.DrsObjectResponseMod
249249
)
250250

251251
async def cleanup_outbox_buckets(
252-
self, *, object_storages_config: S3ObjectStoragesConfig
252+
self,
253+
*,
254+
object_storages_config: S3ObjectStoragesConfig,
253255
):
254256
"""Run cleanup task for all outbox buckets configured in the service config."""
255257
for storage_alias in object_storages_config.object_storages:
@@ -265,16 +267,19 @@ async def cleanup_outbox(self, *, storage_alias: str):
265267
"""
266268
# Run on demand through CLI, so crashing should be ok if the alias is not configured
267269
log.info(
268-
f"Starting outbox cleanup for storage identified by alias '{storage_alias}'."
270+
f"Starting outbox cleanup for storage identified by alias {storage_alias}."
269271
)
270272
try:
271273
bucket_id, object_storage = self._object_storages.for_alias(storage_alias)
272-
except KeyError as exc:
274+
except KeyError:
273275
storage_alias_not_configured = self.StorageAliasNotConfiguredError(
274276
alias=storage_alias
275277
)
276278
log.critical(storage_alias_not_configured)
277-
raise storage_alias_not_configured from exc
279+
log.warning(
280+
f"Skipping outbox cleanup for storage {storage_alias} as it is not configured."
281+
)
282+
return
278283

279284
threshold = utc_dates.now_as_utc() - timedelta(
280285
days=self._config.outbox_cache_timeout
@@ -294,13 +299,14 @@ async def cleanup_outbox(self, *, storage_alias: str):
294299
except ResourceNotFoundError as error:
295300
cleanup_error = self.CleanupError(object_id=object_id, from_error=error)
296301
log.critical(cleanup_error)
297-
raise cleanup_error from error
302+
log.warning(
303+
f"Object with id {object_id} in storage {storage_alias} not found in database, skipping."
304+
)
305+
continue
298306

299307
# only remove file if last access is later than oubtox_cache_timeout days ago
300308
if drs_object.last_accessed <= threshold:
301-
log.info(
302-
f"Deleting object '{object_id}' from storage '{storage_alias}'."
303-
)
309+
log.info(f"Deleting object {object_id} from storage {storage_alias}.")
304310
try:
305311
await object_storage.delete_object(
306312
bucket_id=bucket_id, object_id=object_id
@@ -313,7 +319,10 @@ async def cleanup_outbox(self, *, storage_alias: str):
313319
object_id=object_id, from_error=error
314320
)
315321
log.critical(cleanup_error)
316-
raise cleanup_error from error
322+
log.warning(
323+
f"Could not delete object with id {object_id} from storage {storage_alias}."
324+
)
325+
continue
317326

318327
async def register_new_file(self, *, file: models.DrsObjectBase):
319328
"""Register a file as a new DRS Object."""

services/dcs/src/dcs/ports/inbound/data_repository.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ class CleanupError(RuntimeError):
3939
"""
4040

4141
def __init__(self, *, object_id: str, from_error: Exception):
42-
message = (
43-
f"Could not remove object {object_id} from outbox: {str(from_error)}"
44-
)
42+
message = f"Could not remove object {object_id} from outbox bucket: {str(from_error)}"
4543
super().__init__(message)
4644

4745
class DrsObjectNotFoundError(RuntimeError):

services/dcs/tests_dcs/test_typical_journey.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""Tests typical user journeys"""
1717

1818
import json
19+
import logging
1920
import re
2021

2122
import httpx
@@ -220,7 +221,7 @@ async def test_happy_deletion(
220221
)
221222

222223

223-
async def test_bucket_cleanup(cleanup_fixture: CleanupFixture):
224+
async def test_bucket_cleanup(cleanup_fixture: CleanupFixture, caplog):
224225
"""Test multiple outbox bucket cleanup handling."""
225226
data_repository = cleanup_fixture.joint.data_repository
226227

@@ -246,7 +247,15 @@ async def test_bucket_cleanup(cleanup_fixture: CleanupFixture):
246247
object_id=expired_object.object_id,
247248
)
248249

249-
with pytest.raises(data_repository.StorageAliasNotConfiguredError):
250+
with caplog.at_level(logging.ERROR):
250251
await data_repository.cleanup_outbox(
251252
storage_alias=cleanup_fixture.joint.endpoint_aliases.fake
252253
)
254+
255+
expected_message = str(
256+
data_repository.StorageAliasNotConfiguredError(
257+
alias=cleanup_fixture.joint.endpoint_aliases.fake
258+
)
259+
)
260+
261+
assert expected_message in caplog.records[0].message

0 commit comments

Comments
 (0)