-
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 (#1557)
* Initial implementation of JobReport with SourceManager usage * Limit concurrent units * Only save the last JobReport per handle
- Loading branch information
1 parent
3897454
commit e391e89
Showing
4 changed files
with
339 additions
and
19 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.