feat: add context support to error handlers for improved cancellation and error management

This commit is contained in:
2026-04-08 23:07:41 -05:00
parent d3a3b26bb3
commit 0ee5d9032c
3 changed files with 76 additions and 32 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"context"
"fmt"
log "github.com/sirupsen/logrus"
@@ -16,18 +17,30 @@ func (e *JobError) Error() string {
if e.Prev != nil {
return fmt.Sprintf("%s: %v", e.Msg, e.Prev)
}
return e.Msg
}
func jobErrorHandler(chErrorsIn <-chan JobError) error {
for err := range chErrorsIn {
if err.ShouldCancelJob {
return &err
func jobErrorHandler(ctx context.Context, chErrorsIn <-chan JobError) error {
for {
if ctx.Err() != nil {
return nil
}
log.Error(err)
}
select {
case <-ctx.Done():
return nil
return nil
case err, ok := <-chErrorsIn:
if !ok {
return nil
}
if err.ShouldCancelJob {
return &err
}
log.Error(err)
}
}
}