refactor: remove extractor error channel and simplify retry logic in mssql and postgres extractors
This commit is contained in:
@@ -200,12 +200,10 @@ func (mssqlEx *MssqlExtractor) ExtractWithRetries(
|
||||
chBatchesOut chan<- models.Batch,
|
||||
) (int64, error) {
|
||||
var totalRowsRead int64
|
||||
var fatalErr error
|
||||
delay := time.Duration(time.Second * 1)
|
||||
currentParitition := partition
|
||||
|
||||
for fatalErr != nil || currentParitition.RetryCounter < 3 {
|
||||
currentParitition.RetryCounter++
|
||||
for {
|
||||
rowsRead, err := mssqlEx.Extract(
|
||||
ctx,
|
||||
tableInfo,
|
||||
@@ -215,33 +213,36 @@ func (mssqlEx *MssqlExtractor) ExtractWithRetries(
|
||||
indexPrimaryKey,
|
||||
chBatchesOut,
|
||||
)
|
||||
totalRowsRead += rowsRead
|
||||
|
||||
if rowsRead > 0 {
|
||||
totalRowsRead += int64(rowsRead)
|
||||
if err == nil {
|
||||
return totalRowsRead, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
var exError *custom_errors.ExtractorError
|
||||
if errors.As(err, &exError) {
|
||||
if exError.HasLastId {
|
||||
currentParitition.ParentId = exError.Partition.Id
|
||||
currentParitition.Id = uuid.New()
|
||||
currentParitition.Range.Min = exError.LastId
|
||||
currentParitition.Range.IsMinInclusive = false
|
||||
}
|
||||
var exError *custom_errors.ExtractorError
|
||||
if errors.As(err, &exError) {
|
||||
currentParitition.RetryCounter++
|
||||
|
||||
time.Sleep(delay)
|
||||
} else {
|
||||
fatalErr = err
|
||||
if currentParitition.RetryCounter > 3 {
|
||||
return totalRowsRead, &custom_errors.JobError{
|
||||
Msg: fmt.Sprintf("Partition %v reached max retries", exError.Partition.Id),
|
||||
Prev: err,
|
||||
}
|
||||
}
|
||||
|
||||
if exError.HasLastId {
|
||||
currentParitition.ParentId = exError.Partition.Id
|
||||
currentParitition.Id = uuid.New()
|
||||
currentParitition.Range.Min = exError.LastId
|
||||
currentParitition.Range.IsMinInclusive = false
|
||||
}
|
||||
|
||||
time.Sleep(delay)
|
||||
continue
|
||||
}
|
||||
|
||||
break
|
||||
return totalRowsRead, err
|
||||
}
|
||||
|
||||
return totalRowsRead, fatalErr
|
||||
}
|
||||
|
||||
func (mssqlEx *MssqlExtractor) Consume(
|
||||
@@ -294,6 +295,7 @@ func (mssqlEx *MssqlExtractor) Consume(
|
||||
indexPrimaryKey,
|
||||
chBatchesOut,
|
||||
)
|
||||
wgActivePartitions.Done()
|
||||
|
||||
if rowsReadResult > 0 {
|
||||
atomic.AddInt64(rowsRead, int64(rowsReadResult))
|
||||
@@ -317,8 +319,6 @@ func (mssqlEx *MssqlExtractor) Consume(
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
wgActivePartitions.Done()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user