feat: refactor models to improve type handling and enhance error management across migration processes
This commit is contained in:
@@ -8,6 +8,9 @@ import (
|
||||
"time"
|
||||
|
||||
"git.ksdemosapps.com/kylesoda/go-migrate/internal/app/config"
|
||||
"git.ksdemosapps.com/kylesoda/go-migrate/internal/app/custom_errors"
|
||||
"git.ksdemosapps.com/kylesoda/go-migrate/internal/app/etl/extractor"
|
||||
"git.ksdemosapps.com/kylesoda/go-migrate/internal/app/models"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
_ "github.com/microsoft/go-mssqldb"
|
||||
@@ -44,11 +47,11 @@ func processMigrationJob(
|
||||
log.Error("Unexpected error calculating batch ranges: ", err)
|
||||
}
|
||||
|
||||
chJobErrors := make(chan JobError, job.QueueSize)
|
||||
chBatches := make(chan Batch, job.QueueSize)
|
||||
chExtractorErrors := make(chan ExtractorError, job.QueueSize)
|
||||
chChunksRaw := make(chan Chunk, job.QueueSize)
|
||||
chChunksTransformed := make(chan Chunk, job.QueueSize)
|
||||
chJobErrors := make(chan custom_errors.JobError, job.QueueSize)
|
||||
chBatches := make(chan models.Batch, job.QueueSize)
|
||||
chExtractorErrors := make(chan custom_errors.ExtractorError, job.QueueSize)
|
||||
chChunksRaw := make(chan models.Chunk, job.QueueSize)
|
||||
chChunksTransformed := make(chan models.Chunk, job.QueueSize)
|
||||
chLoadersErrors := make(chan LoaderError, job.QueueSize)
|
||||
|
||||
var wgActiveBatches sync.WaitGroup
|
||||
@@ -58,21 +61,34 @@ func processMigrationJob(
|
||||
var wgLoaders sync.WaitGroup
|
||||
|
||||
go func() {
|
||||
if err := jobErrorHandler(jobCtx, chJobErrors); err != nil {
|
||||
if err := custom_errors.JobErrorHandler(jobCtx, chJobErrors); err != nil {
|
||||
cancel()
|
||||
result.Error = err
|
||||
}
|
||||
}()
|
||||
|
||||
go extractorErrorHandler(jobCtx, chExtractorErrors, chBatches, chJobErrors, &wgActiveBatches)
|
||||
go custom_errors.ExtractorErrorHandler(jobCtx, chExtractorErrors, chBatches, chJobErrors, &wgActiveBatches)
|
||||
go loaderErrorHandler(jobCtx, chLoadersErrors, chChunksTransformed, chJobErrors, &wgActiveChunks)
|
||||
|
||||
maxExtractors := min(job.MaxExtractors, len(batches))
|
||||
log.Infof("Starting %d extractor(s)...", maxExtractors)
|
||||
|
||||
exMssql := extractor.NewMssqlExtractor(sourceDb)
|
||||
|
||||
for range maxExtractors {
|
||||
wgExtractors.Go(func() {
|
||||
extractFromMssql(jobCtx, sourceDb, job.SourceTable, sourceColTypes, job.ChunkSize, chBatches, chChunksRaw, chExtractorErrors, chJobErrors, &wgActiveBatches, &rowsRead)
|
||||
exMssql.Exec(
|
||||
jobCtx,
|
||||
job.SourceTable,
|
||||
sourceColTypes,
|
||||
job.ChunkSize,
|
||||
chBatches,
|
||||
chChunksRaw,
|
||||
chExtractorErrors,
|
||||
chJobErrors,
|
||||
&wgActiveBatches,
|
||||
&rowsRead,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -132,7 +148,7 @@ func processMigrationJob(
|
||||
return result
|
||||
}
|
||||
|
||||
func logColumnTypes(columnTypes []ColumnType, label string) {
|
||||
func logColumnTypes(columnTypes []models.ColumnType, label string) {
|
||||
log.Debug(label)
|
||||
|
||||
for _, col := range columnTypes {
|
||||
|
||||
Reference in New Issue
Block a user