Skip to content

Commit

Permalink
Allow updates to fail, and use old map if so
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyui committed Jan 31, 2025
1 parent 7fb0959 commit 7cfc867
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions app/usecases/akatsuki_beatmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,19 @@ async def fetch_one_by_id(beatmap_id: int) -> AkatsukiBeatmap | None:
beatmap = await akatsuki_beatmaps.create_or_replace(new_beatmap)

elif beatmap.deserves_update:
beatmap = await _update_from_osu_api(beatmap)
if beatmap is None:
# (we may have deleted the map during the update)
return None
try:
beatmap = await _update_from_osu_api(beatmap)
if beatmap is None:
# (we may have deleted the map during the update)
return None
except Exception:
logging.warning(
"Failed to update beatmap requested by id (using old beatmap for now)",
extra={
"beatmap": beatmap.model_dump() if beatmap else None,
"beatmap_id": beatmap_id,
},
)

return beatmap

Expand All @@ -177,9 +186,18 @@ async def fetch_one_by_md5(beatmap_md5: str) -> AkatsukiBeatmap | None:
beatmap = await akatsuki_beatmaps.create_or_replace(new_beatmap)

elif beatmap.deserves_update:
beatmap = await _update_from_osu_api(beatmap)
if beatmap is None:
# (we may have deleted the map during the update)
return None
try:
beatmap = await _update_from_osu_api(beatmap)
if beatmap is None:
# (we may have deleted the map during the update)
return None
except Exception:
logging.warning(
"Failed to update beatmap requested by md5 (using old beatmap for now)",
extra={
"beatmap": beatmap.model_dump() if beatmap else None,
"beatmap_md5": beatmap_md5,
},
)

return beatmap

0 comments on commit 7cfc867

Please sign in to comment.