From 78f6e4c8cc1d4ec3815bc1c917dc01ab328bdb12 Mon Sep 17 00:00:00 2001 From: Nick Dubelman Date: Tue, 18 Jun 2024 10:59:02 -0700 Subject: [PATCH] change where target connect happens (#11) --- sync.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sync.go b/sync.go index 275f5b6..ac73b70 100644 --- a/sync.go +++ b/sync.go @@ -41,11 +41,6 @@ func (job JobConfig) syncTargets() (string, []SyncResult, error) { primaryKeyIndices: primaryKeyIndices, columns: job.Columns, } - - // Connect to each target - if err := targets[i].connect(); err != nil { - return "", nil, err - } } // Get all rows from the source table and put them in a map by their primary key @@ -70,6 +65,15 @@ func (job JobConfig) syncTargets() (string, []SyncResult, error) { go func(target table) { defer wg.Done() + // Connect to each target + if err := target.connect(); err != nil { + resultChan <- SyncResult{ + Target: target.config, + Error: err, + } + return + } + checksum, synced, err := target.syncTarget(sourceChecksum, sourceMap) target.Close() // Close the target's connection pool