-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of JobReport with SourceManager usage
- Loading branch information
1 parent
f925da7
commit b8ed270
Showing
4 changed files
with
335 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package sources | ||
|
||
import ( | ||
"errors" | ||
"sync" | ||
"time" | ||
) | ||
|
||
// JobReport aggregates information about a run of a Source. | ||
type JobReport struct { | ||
SourceID int64 | ||
JobID int64 | ||
StartTime time.Time | ||
EndTime time.Time | ||
TotalChunks uint64 | ||
errors []error | ||
errorsLock sync.Mutex | ||
} | ||
|
||
// AddError adds a non-nil error to the aggregate of errors encountered during | ||
// scanning. | ||
func (jr *JobReport) AddError(err error) { | ||
if err == nil { | ||
return | ||
} | ||
jr.errorsLock.Lock() | ||
defer jr.errorsLock.Unlock() | ||
jr.errors = append(jr.errors, err) | ||
} | ||
|
||
// Errors joins all aggregated errors into one. If there were no errors, nil is | ||
// returned. errors.Is can be used to check for specific errors. | ||
func (jr *JobReport) Errors() error { | ||
jr.errorsLock.Lock() | ||
defer jr.errorsLock.Unlock() | ||
return errors.Join(jr.errors...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.