pgflo / pg_flo

Stream, transform, and route PostgreSQL data in real-time.
https://pgflo.io
Apache License 2.0
664 stars 13 forks source link

Move towards simpler interfaces and good lifecycle management hygiene #52

Closed shayonj closed 1 day ago

shayonj commented 1 day ago

Caller can now use it like this:

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

replicator, err := factory.CreateReplicator(config, natsClient)
if err != nil {
    log.Fatal(err)
}

// Start replication
if err := replicator.Start(ctx); err != nil {
    log.Fatal(err)
}

// Handle shutdown signal
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
<-sigCh

// Stop replication
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 30*time.Second)
defer shutdownCancel()

if err := replicator.Stop(shutdownCtx); err != nil {
    log.Error(err)
}