Skip to content

Commit f1bf24b

Browse files
committed
Cache busting for wot
1 parent 07658f4 commit f1bf24b

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

src/ghga_connector/core/downloading/api_calls.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232

3333
async def _get_authorization(
34-
file_id: str, work_package_accessor: WorkPackageAccessor
34+
file_id: str, work_package_accessor: WorkPackageAccessor, bust_cache: bool = False
3535
) -> httpx.Headers:
3636
"""
3737
Fetch work order token using accessor and prepare DCS endpoint URL and headers for a
@@ -41,7 +41,9 @@ async def _get_authorization(
4141
for at least another `CACHE_MIN_FRESH` seconds.
4242
"""
4343
# fetch a work order token
44-
decrypted_token = await work_package_accessor.get_work_order_token(file_id=file_id)
44+
decrypted_token = await work_package_accessor.get_work_order_token(
45+
file_id=file_id, bust_cache=bust_cache
46+
)
4547
# build headers
4648
headers = httpx.Headers(
4749
{
@@ -71,7 +73,7 @@ async def get_envelope_authorization(
7173

7274

7375
async def get_file_authorization(
74-
file_id: str, work_package_accessor: WorkPackageAccessor
76+
file_id: str, work_package_accessor: WorkPackageAccessor, bust_cache: bool = False
7577
) -> UrlAndHeaders:
7678
"""
7779
Fetch work order token using accessor and prepare DCS endpoint URL and headers to get
@@ -80,7 +82,9 @@ async def get_file_authorization(
8082
# build URL
8183
url = f"{work_package_accessor.dcs_api_url}/objects/{file_id}"
8284
headers = await _get_authorization(
83-
file_id=file_id, work_package_accessor=work_package_accessor
85+
file_id=file_id,
86+
work_package_accessor=work_package_accessor,
87+
bust_cache=bust_cache,
8488
)
8589
return UrlAndHeaders(url, headers)
8690

src/ghga_connector/core/downloading/batch_processing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ async def _check_file(self, file_id: str) -> None:
218218
url_and_headers = await get_file_authorization(
219219
file_id=file_id,
220220
work_package_accessor=self.work_package_accessor,
221+
bust_cache=True,
221222
)
222223
response = await get_download_url(
223224
client=self.client, url_and_headers=url_and_headers, bust_cache=True

src/ghga_connector/core/downloading/downloader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ async def fetch_download_url(self, bust_cache: bool = False) -> URLResponse:
204204
url_and_headers = await get_file_authorization(
205205
file_id=self._file_id,
206206
work_package_accessor=self._work_package_accessor,
207+
bust_cache=True,
207208
)
208209
response = await get_download_url(
209210
client=self._client,

src/ghga_connector/core/work_package.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ async def get_package_files(self) -> dict[str, str]:
9292
work_package = response.json()
9393
return work_package["files"]
9494

95-
async def get_work_order_token(self, *, file_id: str) -> str:
95+
async def get_work_order_token(
96+
self, *, file_id: str, bust_cache: bool = False
97+
) -> str:
9698
"""Call WPS endpoint to retrieve and decrypt work order token."""
9799
url = f"{self.api_url}/work-packages/{self.package_id}/files/{file_id}/work-order-tokens"
98100

@@ -103,6 +105,12 @@ async def get_work_order_token(self, *, file_id: str) -> str:
103105
"Cache-Control": f"min-fresh={CACHE_MIN_FRESH}",
104106
}
105107
)
108+
if bust_cache:
109+
# update cache-control headers to get fresh response from source
110+
cache_control_headers = headers.get("Cache-Control")
111+
cache_control_headers = [cache_control_headers, "max-age=0"]
112+
headers["Cache-Control"] = ",".join(cache_control_headers)
113+
106114
response = await self._call_url(fn=self.client.post, headers=headers, url=url)
107115

108116
status_code = response.status_code

0 commit comments

Comments
 (0)