package lighthouse import ( "context" "edge-infra.dev/pkg/edge/lighthouse/config" "edge-infra.dev/pkg/lib/gcp/pubsub" "edge-infra.dev/pkg/lib/logging" ) // Run creates the lighthouse and then starts it. func Run() error { log := logging.NewLogger().WithName("lighthouse") ctx := context.Background() syscfg, err := config.Init(ctx, nil) if err != nil { log.Error(err, "failed to init system configuration") return err } manager, err := pubsub.NewWithOptions(ctx, syscfg.ProjectID) if err != nil { log.Error(err, "failed to setup pubsub client") return err } lstner := NewWatchTower(). SetProjectID(syscfg.ProjectID). SetTopicID(syscfg.TopicID). AddPubsubClient(manager). AddListener(syscfg.DatabaseCfg, syscfg.DatabaseCfg.ConnectionString(true), 0, 0, log) watch, err := WatchCfg(ctx, syscfg, lstner, log) if err != nil { log.Error(err, "failed to watch lighthouse configmap") return err } defer watch.Stop() log.Info("Lighthouse has started and is listening to Postgres notifications and events...") lstner.Stream(ctx, log) return nil }