refactor: inline single-use helpers in jikan client

This commit is contained in:
2026-06-23 17:16:36 +02:00
committed by Milas Holsting
parent 7e26f2ee77
commit e40e657d60

View File

@@ -98,7 +98,7 @@ func jikanCacheLogLevel(source string, err error) observability.LogLevel {
}
func (c *Client) logJikanCache(cacheKey string, source string, startedAt time.Time, err error) {
if isContextError(err) {
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
return
}
@@ -121,18 +121,6 @@ func (c *Client) logJikanCache(cacheKey string, source string, startedAt time.Ti
)
}
func truncateErrorMessage(message string) string {
if len(message) <= 400 {
return message
}
return message[:400]
}
func isContextError(err error) bool {
return errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)
}
// notifyRetryWorker signals the retry worker, non-blocking.
func (c *Client) notifyRetryWorker() {
select {
@@ -155,9 +143,14 @@ func (c *Client) EnqueueAnimeFetchRetry(parentCtx context.Context, animeID int,
ctx, cancel := context.WithTimeout(parentCtx, 2*time.Second)
defer cancel()
message := cause.Error()
if len(message) > 400 {
message = message[:400]
}
err := c.db.EnqueueAnimeFetchRetry(ctx, db.EnqueueAnimeFetchRetryParams{
AnimeID: int64(animeID),
LastError: truncateErrorMessage(cause.Error()),
LastError: message,
})
if err != nil {
observability.Warn(