feat: implement extractor error handling and batch processing for MSSQL and Postgres
This commit is contained in:
47
internal/app/custom_errors/job.error.go
Normal file
47
internal/app/custom_errors/job.error.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package custom_errors
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type JobError struct {
|
||||
ShouldCancelJob bool
|
||||
Msg string
|
||||
Prev error
|
||||
}
|
||||
|
||||
func (e *JobError) Error() string {
|
||||
if e.Prev != nil {
|
||||
return fmt.Sprintf("%s: %v", e.Msg, e.Prev)
|
||||
}
|
||||
|
||||
return e.Msg
|
||||
}
|
||||
|
||||
func JobErrorHandler(ctx context.Context, chErrorsIn <-chan JobError) error {
|
||||
for {
|
||||
if ctx.Err() != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
|
||||
case err, ok := <-chErrorsIn:
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err.ShouldCancelJob {
|
||||
log.Error(err.Msg, " - ", err.Prev)
|
||||
return &err
|
||||
}
|
||||
|
||||
log.Error(err.Msg, " - ", err.Prev)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user