The fetcher's "saved opportunities" and "fetched opportunities" lines now name the source

This commit is contained in:
bwilliams committed 2026-10-21 14:36:22 +01:00
1 parent 50ee510520
commit c678b02662
4 files changed
+21 -3

No files matched your search

+7
View File
@@ -246,6 +246,9 @@ func (f *Fetcher) startFrom(
// Opportunities that match the skip rules (see WithSkipRules) are marked
// Skipped first. The store keeps the marks of an opportunity it already
// has, so only new ones are skipped.
//
// Each save is one worker's, so its lines are logged with the first
// opportunity's Source.
func (f *Fetcher) save(
ctx context.Context,
logger *slog.Logger,
@@ -255,6 +258,10 @@ func (f *Fetcher) save(
return nil
}
if len(opportunities) > 0 {
logger = logger.With("source", opportunities[0].Source)
}
filters := f.markSkipped(opportunities)
result, err := f.store.SaveOpportunities(ctx, opportunities)
+4 -1
View File
@@ -921,9 +921,12 @@ func TestSaveSkipsNewOpportunities(t *testing.T) {
if !skipped(s) {
t.Error("a new matching opportunity wasn't skipped")
}
// Both lines name the source.
for _, want := range []string{
"msg=\"saved opportunities\" source=FindATender component=fetcher",
"skipped_opportunities=1",
"msg=\"skipped new opportunity\" component=fetcher uuid=ocds-1 filter=IT",
"msg=\"skipped new opportunity\" source=FindATender component=fetcher " +
"uuid=ocds-1 filter=IT",
} {
if !strings.Contains(logged.String(), want) {
t.Errorf("log has no %q:\n%s", want, logged.String())
+5 -1
View File
@@ -86,7 +86,11 @@ func fetchFindATender(
return nil, ErrNoNewReleases
}
tagged(logger).Info("fetched opportunities", "count", len(opportunities))
tagged(logger).Info(
"fetched opportunities",
"source", findATenderSource,
"count", len(opportunities),
)
return opportunities, err
}
+5 -1
View File
@@ -89,7 +89,11 @@ func fetchFTSMock(
opportunity.Source = ftsMockSource
}
tagged(logger).Info("fetched opportunities", "count", len(opportunities))
tagged(logger).Info(
"fetched opportunities",
"source", ftsMockSource,
"count", len(opportunities),
)
return opportunities, err
}