debug(cdi): logs de diagnóstico em ApplyYield e fetchCDIRates
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -95,16 +96,20 @@ func (s *CDIYieldService) ApplyYield(ctx context.Context, a *model.Account) erro
|
||||
startDate = t.AddDate(0, 0, 1).Format("2006-01-02")
|
||||
}
|
||||
|
||||
log.Printf("[cdi] account=%d lastYieldDate=%v startDate=%s yesterday=%s", a.ID, a.LastYieldDate, startDate, yesterday)
|
||||
|
||||
if startDate > yesterday {
|
||||
// nothing to calculate yet
|
||||
log.Printf("[cdi] account=%d early return (already up to date)", a.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Printf("[cdi] account=%d calling BCB for [%s, %s]", a.ID, startDate, yesterday)
|
||||
rates, err := s.fetchCDIRates(startDate, yesterday)
|
||||
if err != nil {
|
||||
// BCB API unreachable — skip silently; will retry next load
|
||||
log.Printf("[cdi] account=%d BCB error: %v", a.ID, err)
|
||||
return nil
|
||||
}
|
||||
log.Printf("[cdi] account=%d BCB returned %d rates", a.ID, len(rates))
|
||||
if len(rates) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -146,10 +151,16 @@ func (s *CDIYieldService) ApplyYield(ctx context.Context, a *model.Account) erro
|
||||
AccountID: &a.ID,
|
||||
}
|
||||
if _, err := s.txRepo.Create(ctx, tx); err != nil {
|
||||
log.Printf("[cdi] account=%d txRepo.Create error: %v", a.ID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return s.accountRepo.UpdateLastYieldDate(ctx, a.ID, yesterday)
|
||||
if err := s.accountRepo.UpdateLastYieldDate(ctx, a.ID, yesterday); err != nil {
|
||||
log.Printf("[cdi] account=%d UpdateLastYieldDate error: %v", a.ID, err)
|
||||
return err
|
||||
}
|
||||
log.Printf("[cdi] account=%d yield applied OK, lastYieldDate → %s", a.ID, yesterday)
|
||||
return nil
|
||||
}
|
||||
|
||||
type bcbEntry struct {
|
||||
@@ -162,8 +173,10 @@ func (s *CDIYieldService) fetchCDIRates(startDate, endDate string) ([]bcbEntry,
|
||||
if s.cache.covers(startDate, endDate) {
|
||||
entries := s.cache.get(startDate, endDate)
|
||||
s.cache.mu.RUnlock()
|
||||
log.Printf("[cdi] cache HIT [%s, %s] → %d entries", startDate, endDate, len(entries))
|
||||
return entries, nil
|
||||
}
|
||||
log.Printf("[cdi] cache MISS [%s, %s] (minDate=%s maxDate=%s valid=%v)", startDate, endDate, s.cache.minDate, s.cache.maxDate, s.cache.valid())
|
||||
s.cache.mu.RUnlock()
|
||||
|
||||
s.cache.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user