fix: handle jikan rate limits gracefully instead of dropping data

This commit is contained in:
2026-04-08 17:17:14 +02:00
parent 44a0e9499d
commit 22955c0018
2 changed files with 13 additions and 9 deletions

View File

@@ -79,8 +79,9 @@ func (s *Service) GetWatchingAnime(ctx context.Context, userID string) ([]templa
for _, row := range rows {
anime, err := s.jikanClient.GetAnimeByID(int(row.AnimeID))
if err != nil {
// Skip if we can't fetch anime details
continue
// Instead of skipping, we still append it, but without the extra Jikan details
// This prevents anime from vanishing from the watchlist when Jikan rate limits us.
anime = jikan.Anime{}
}
result = append(result, templates.WatchingAnimeWithDetails{
Entry: row,

View File

@@ -71,7 +71,16 @@ func (w *Worker) syncRelations(ctx context.Context) {
for _, a := range animes {
func() {
// Always mark as synced and sleep so the queue advances even on error.
animeData, err := w.client.GetAnimeByID(int(a.ID))
if err != nil {
log.Printf("worker: failed to fetch anime details for %d: %v", a.ID, err)
// Sleep a bit on error to respect rate limits, but DO NOT mark as synced
// so it will be retried on the next worker run.
time.Sleep(2 * time.Second)
return
}
// If we got here, we successfully fetched the data, so we mark it as synced.
defer func() {
err := w.db.MarkRelationsSynced(ctx, a.ID)
if err != nil {
@@ -80,12 +89,6 @@ func (w *Worker) syncRelations(ctx context.Context) {
time.Sleep(400 * time.Millisecond)
}()
animeData, err := w.client.GetAnimeByID(int(a.ID))
if err != nil {
log.Printf("worker: failed to fetch anime details for %d: %v", a.ID, err)
return
}
for _, rel := range animeData.Relations {
for _, entry := range rel.Entry {
if entry.Type == "anime" {