feat: enhance migration job processing with detailed metrics and error handling
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"git.ksdemosapps.com/kylesoda/go-migrate/internal/app/config"
|
||||
@@ -25,6 +26,7 @@ func loadRowsPostgres(
|
||||
chErrorsOut chan<- LoaderError,
|
||||
chJobErrorsOut chan<- JobError,
|
||||
wgActiveChunks *sync.WaitGroup,
|
||||
rowsLoaded *int64,
|
||||
) {
|
||||
tableId := pgx.Identifier{tableInfo.Schema, tableInfo.Table}
|
||||
colNames := Map(columns, func(col ColumnType) string {
|
||||
@@ -44,7 +46,7 @@ func loadRowsPostgres(
|
||||
return
|
||||
}
|
||||
|
||||
if abort := loadChunkPostgres(ctx, db, tableId, colNames, chunk, chErrorsOut, chJobErrorsOut, wgActiveChunks); abort {
|
||||
if abort := loadChunkPostgres(ctx, db, tableId, colNames, chunk, chErrorsOut, chJobErrorsOut, wgActiveChunks, rowsLoaded); abort {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -60,6 +62,7 @@ func loadChunkPostgres(
|
||||
chErrorsOut chan<- LoaderError,
|
||||
chJobErrorsOut chan<- JobError,
|
||||
wgActiveChunks *sync.WaitGroup,
|
||||
rowsLoaded *int64,
|
||||
) (abort bool) {
|
||||
chunkStartTime := time.Now()
|
||||
_, err := db.CopyFrom(
|
||||
@@ -99,6 +102,7 @@ func loadChunkPostgres(
|
||||
|
||||
log.Infof("Loaded chunk: %d rows in %v (%.0f rows/sec)", len(chunk.Data), chunkDuration, rowsPerSec)
|
||||
|
||||
atomic.AddInt64(rowsLoaded, int64(len(chunk.Data)))
|
||||
wgActiveChunks.Done()
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user