Handle anime refresh errors

This commit is contained in:
2026-06-20 18:28:41 +02:00
committed by Milas Holsting
parent f137e6be58
commit 6bf91f293b

View File

@@ -3,6 +3,7 @@ package jikan
import ( import (
"context" "context"
"fmt" "fmt"
"mal/internal/observability"
"time" "time"
) )
@@ -38,7 +39,9 @@ func (c *Client) WarmAnimeRecommendations(id int) {
c.runAsyncRefresh(func(ctx context.Context) { c.runAsyncRefresh(func(ctx context.Context) {
var resp RecommendationsResponse var resp RecommendationsResponse
_ = c.getWithCache(ctx, cacheKey, 24*time.Hour, url, &resp) if err := c.getWithCache(ctx, cacheKey, 24*time.Hour, url, &resp); err != nil {
c.EnqueueAnimeFetchRetry(ctx, id, err)
}
}) })
} }
@@ -71,7 +74,7 @@ func (c *Client) GetAnimeByID(ctx context.Context, id int) (Anime, error) {
func (c *Client) refreshAnimeByID(ctx context.Context, id int) (Anime, error) { func (c *Client) refreshAnimeByID(ctx context.Context, id int) (Anime, error) {
cacheKey := fmt.Sprintf("anime:%d", id) cacheKey := fmt.Sprintf("anime:%d", id)
value, err, _ := c.sf.Do("refresh:"+cacheKey, func() (any, error) { value, err, shared := c.sf.Do("refresh:"+cacheKey, func() (any, error) {
var cached Anime var cached Anime
if c.getCache(ctx, cacheKey, &cached) && cached.MalID != 0 { if c.getCache(ctx, cacheKey, &cached) && cached.MalID != 0 {
return cached, nil return cached, nil
@@ -95,6 +98,14 @@ func (c *Client) refreshAnimeByID(ctx context.Context, id int) (Anime, error) {
if err != nil { if err != nil {
return Anime{}, err return Anime{}, err
} }
if shared {
observability.Info(
"jikan_anime_refresh_shared",
"jikan",
"",
map[string]any{"anime_id": id, "cache_key": cacheKey},
)
}
if anime, ok := value.(Anime); ok && anime.MalID != 0 { if anime, ok := value.(Anime); ok && anime.MalID != 0 {
return anime, nil return anime, nil
@@ -105,6 +116,8 @@ func (c *Client) refreshAnimeByID(ctx context.Context, id int) (Anime, error) {
func (c *Client) refreshAnimeByIDAsync(id int) { func (c *Client) refreshAnimeByIDAsync(id int) {
c.runAsyncRefresh(func(ctx context.Context) { c.runAsyncRefresh(func(ctx context.Context) {
_, _ = c.refreshAnimeByID(ctx, id) if _, err := c.refreshAnimeByID(ctx, id); err != nil {
c.EnqueueAnimeFetchRetry(ctx, id, err)
}
}) })
} }