Строки asn_prefix_cache_row; периодический prune через evobgp-ingest. Co-authored-by: Cursor <[email protected]>
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package ingest
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"time"
|
|
|
|
"evobgp/internal/broker"
|
|
"evobgp/internal/config"
|
|
"evobgp/internal/httpclient"
|
|
"evobgp/internal/pipeline"
|
|
"evobgp/internal/store"
|
|
)
|
|
|
|
// Deps runs lightweight CDN ETag prefetch against the shared store.
|
|
type Deps struct {
|
|
Store store.Backend
|
|
}
|
|
|
|
var lastMaintenance time.Time
|
|
|
|
// 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 {
|
|
log.Fatalf("evobgp-ingest: missing store (pass ingest.Deps from BootstrapWorkers or evobgp-all)")
|
|
}
|
|
hc := httpclient.New(httpclient.DefaultTimeout)
|
|
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 deps.Store != nil && time.Since(lastMaintenance) > time.Hour {
|
|
deps.Store.RunPeriodicMaintenance(ctx)
|
|
lastMaintenance = time.Now()
|
|
}
|
|
prefetchCtx, cancel := context.WithTimeout(ctx, 50*time.Second)
|
|
err := pipeline.PrefetchCDNSourceETags(prefetchCtx, deps.Store, hc)
|
|
cancel()
|
|
if err != nil {
|
|
log.Printf("evobgp-ingest: prefetch: %v", err)
|
|
}
|
|
}
|
|
}
|
|
}
|