Files
EvoBGP/internal/ingest/run.go
T

58 lines
1.2 KiB
Go

package ingest
import (
"context"
"log"
"net/http"
"time"
"evobgp/internal/broker"
"evobgp/internal/config"
"evobgp/internal/pipeline"
"evobgp/internal/store"
)
// Deps runs lightweight CDN ETag prefetch against the shared store.
type Deps struct {
Store store.Backend
}
// Run blocks until ctx is cancelled.
func Run(ctx context.Context, deps *Deps) {
cfg := config.Load()
broker.LogConnect(ctx, cfg.BrokerURL)
if deps == nil || deps.Store == nil {
runStub(ctx)
return
}
hc := &http.Client{Timeout: 45 * time.Second}
t := time.NewTicker(60 * time.Second)
defer t.Stop()
log.Printf("evobgp-ingest: active (CDN conditional GET / ETag prefetch)")
for {
select {
case <-ctx.Done():
log.Printf("evobgp-ingest: stopped")
return
case <-t.C:
if err := pipeline.PrefetchCDNSourceETags(context.Background(), deps.Store, hc); err != nil {
log.Printf("evobgp-ingest: prefetch: %v", err)
}
}
}
}
func runStub(ctx context.Context) {
t := time.NewTicker(60 * time.Second)
defer t.Stop()
log.Printf("evobgp-ingest: idle stub (no store in Deps)")
for {
select {
case <-ctx.Done():
log.Printf("evobgp-ingest: stopped")
return
case <-t.C:
}
}
}