-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract osu file usecases and add s3 writes on new .osu file discovered
- Loading branch information
Showing
2 changed files
with
34 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import logging | ||
|
||
from app.adapters import aws_s3 | ||
from app.adapters import osu_api_v1 | ||
|
||
|
||
async def fetch_beatmap_osu_file_data(beatmap_id: int) -> bytes | None: | ||
beatmap_osu_file_data = await aws_s3.get_object_data(f"/beatmaps/{beatmap_id}.osu") | ||
if beatmap_osu_file_data is None: | ||
beatmap_osu_file_data = await osu_api_v1.fetch_beatmap_osu_file_data(beatmap_id) | ||
if beatmap_osu_file_data is None: | ||
return None | ||
|
||
await aws_s3.save_object_data( | ||
f"/beatmaps/{beatmap_id}.osu", | ||
beatmap_osu_file_data, | ||
) | ||
logging.info( | ||
"Saved beatmap osu file to s3", | ||
extra={"beatmap_id": beatmap_id}, | ||
) | ||
# NOTE: this is a place where .osu files could become desynced | ||
# with akatsuki beatmaps in the mysql database, however we've | ||
# decided to not worry about this for now, as most use cases | ||
# which rely on .osu files will also fetch the beatmap metadata, | ||
# forcing an update to occur. | ||
else: | ||
# TODO: consider cache expiry | ||
... | ||
|
||
return beatmap_osu_file_data |