package render import ( "context" "evobgp/internal/logging" "fmt" "log" "os" "strings" "time" "evobgp/internal/broker" "evobgp/internal/config" "evobgp/internal/store" ) // Deps enables auto-publish of the latest rendered revision to all speakers in each tenant. type Deps struct { Store store.Backend } // Run blocks until ctx is cancelled. With Store set, periodically publishes the head revision for each tenant. func Run(ctx context.Context, deps *Deps) { cfg := config.Load() broker.LogConnect(ctx, cfg.BrokerURL) if deps == nil || deps.Store == nil { log.Fatalf("evobgp-render: missing store (pass render.Deps from BootstrapWorkers or evobgp-all)") } t := time.NewTicker(45 * time.Second) defer t.Stop() auto := strings.TrimSpace(os.Getenv("EVOBGP_RENDER_AUTOPUBLISH")) == "1" if auto { logging.Default().Info(fmt.Sprintf("evobgp-render: active (EVOBGP_RENDER_AUTOPUBLISH=1: publish head revision per tenant)")) } else { logging.Default().Info(fmt.Sprintf("evobgp-render: active (idle publish; set EVOBGP_RENDER_AUTOPUBLISH=1 to auto-publish head revision)")) } for { select { case <-ctx.Done(): logging.Default().Info(fmt.Sprintf("evobgp-render: stopped")) return case <-t.C: if auto { PublishLatestTenantRevision(context.Background(), deps.Store) } } } }