mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 09:48:32 +02:00
refactor: replace gperr.Builder with gperr.Group for concurrent error handling
- Updated various files to utilize gperr.Group for cleaner concurrency error handling. - Removed sync.WaitGroup usage, simplifying the code structure. - Ensured consistent error reporting across different components.
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/url"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@@ -72,43 +71,41 @@ func isNoDataAvailable(err error) bool {
|
||||
}
|
||||
|
||||
func getSystemInfo(ctx context.Context, lastResult *SystemInfo) (*SystemInfo, error) {
|
||||
errs := gperr.NewBuilderWithConcurrency("failed to get system info")
|
||||
errs := gperr.NewGroup("failed to get system info")
|
||||
var s SystemInfo
|
||||
s.Timestamp = time.Now().Unix()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
if !common.MetricsDisableCPU {
|
||||
wg.Go(func() {
|
||||
errs.Add(s.collectCPUInfo(ctx))
|
||||
errs.Go(func() error {
|
||||
return s.collectCPUInfo(ctx)
|
||||
})
|
||||
}
|
||||
if !common.MetricsDisableMemory {
|
||||
wg.Go(func() {
|
||||
errs.Add(s.collectMemoryInfo(ctx))
|
||||
errs.Go(func() error {
|
||||
return s.collectMemoryInfo(ctx)
|
||||
})
|
||||
}
|
||||
if !common.MetricsDisableDisk {
|
||||
wg.Go(func() {
|
||||
errs.Add(s.collectDisksInfo(ctx, lastResult))
|
||||
errs.Go(func() error {
|
||||
return s.collectDisksInfo(ctx, lastResult)
|
||||
})
|
||||
}
|
||||
if !common.MetricsDisableNetwork {
|
||||
wg.Go(func() {
|
||||
errs.Add(s.collectNetworkInfo(ctx, lastResult))
|
||||
errs.Go(func() error {
|
||||
return s.collectNetworkInfo(ctx, lastResult)
|
||||
})
|
||||
}
|
||||
if !common.MetricsDisableSensors {
|
||||
wg.Go(func() {
|
||||
errs.Add(s.collectSensorsInfo(ctx))
|
||||
errs.Go(func() error {
|
||||
return s.collectSensorsInfo(ctx)
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
if errs.HasError() {
|
||||
result := errs.Wait()
|
||||
if result.HasError() {
|
||||
allWarnings := gperr.NewBuilder("")
|
||||
allErrors := gperr.NewBuilder("failed to get system info")
|
||||
errs.ForEach(func(err error) {
|
||||
result.ForEach(func(err error) {
|
||||
warnings := new(warning.Warning)
|
||||
if errors.As(err, &warnings) {
|
||||
for _, warning := range warnings.List {
|
||||
|
||||
Reference in New Issue
Block a user