Minor fixes:
- Fixed function name typo - Fetcher/Run now returns a combination of errors if any workers error out. All other workers are ordered to shutdown if any one does error out - findATender now returns a pointer instead of an instance from New
This commit is contained in:
1 parent
5cb3601e1f
commit
005b335371
6 files changed
+31
-15
No files matched your search
@@ -2,6 +2,7 @@ package fetcher
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sync"
|
||||
@@ -13,10 +14,21 @@ import (
|
||||
|
||||
var ErrNoNewReleases = fmt.Errorf("%w: no new releases", util.ErrWorkerNoWork)
|
||||
|
||||
// Run starts a worker for each enabled source and blocks until every worker
|
||||
// has stopped. Workers stop when ctx is cancelled, or when any worker stops
|
||||
// with an error, which starts a shutdown of all of them. The errors are
|
||||
// logged as they happen and returned joined; nil means a clean shutdown.
|
||||
func Run(
|
||||
ctx context.Context, conf *config.JobSearchConfig, since time.Time,
|
||||
) {
|
||||
var wg sync.WaitGroup
|
||||
) error {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
var (
|
||||
wg sync.WaitGroup
|
||||
mu sync.Mutex
|
||||
errs []error
|
||||
)
|
||||
|
||||
start := func(
|
||||
name string,
|
||||
@@ -26,7 +38,11 @@ func Run(
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := run(ctx, conf, since); err != nil {
|
||||
slog.Error("source stopped", "source", name, "err", err)
|
||||
slog.Error("source stopped, shutting down", "source", name, "err", err)
|
||||
mu.Lock()
|
||||
errs = append(errs, fmt.Errorf("%s: %w", name, err))
|
||||
mu.Unlock()
|
||||
cancel()
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -42,4 +58,5 @@ func Run(
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
Reference in new issue
Block a user