- 20 Go source files, single 16MB binary - SQLite + FTS5 full-text search (pure Go, no CGO) - BCB integration: Selic, CDI, IPCA, USD/BRL, EUR/BRL - CVM integration: 2,524 companies from registry - Fiber v2 REST API with 42 handlers - Auto-seeds on first run (~5s for BCB + CVM) - Token bucket rate limiter, optional API key auth - Periodic sync scheduler (configurable) - Graceful shutdown, structured logging (slog) - All endpoints tested with real data
29 lines
567 B
Go
29 lines
567 B
Go
package fetcher
|
|
|
|
import (
|
|
"log/slog"
|
|
"time"
|
|
|
|
"github.com/sentinela-go/internal/db"
|
|
)
|
|
|
|
func StartScheduler(database *db.DB, interval time.Duration, stop <-chan struct{}) {
|
|
ticker := time.NewTicker(interval)
|
|
defer ticker.Stop()
|
|
|
|
for {
|
|
select {
|
|
case <-ticker.C:
|
|
slog.Info("scheduled sync starting")
|
|
if err := FetchAllBCB(database); err != nil {
|
|
slog.Error("scheduled BCB sync failed", "error", err)
|
|
}
|
|
if err := FetchAllCVM(database); err != nil {
|
|
slog.Error("scheduled CVM sync failed", "error", err)
|
|
}
|
|
case <-stop:
|
|
return
|
|
}
|
|
}
|
|
}
|