The fetcher's "saved opportunities" and "fetched opportunities" lines now name the source
This commit is contained in:
1 parent
50ee510520
commit
c678b02662
4 files changed
+21
-3
No files matched your search
@@ -246,6 +246,9 @@ func (f *Fetcher) startFrom(
|
|||||||
// Opportunities that match the skip rules (see WithSkipRules) are marked
|
// Opportunities that match the skip rules (see WithSkipRules) are marked
|
||||||
// Skipped first. The store keeps the marks of an opportunity it already
|
// Skipped first. The store keeps the marks of an opportunity it already
|
||||||
// has, so only new ones are skipped.
|
// 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(
|
func (f *Fetcher) save(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
logger *slog.Logger,
|
logger *slog.Logger,
|
||||||
@@ -255,6 +258,10 @@ func (f *Fetcher) save(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(opportunities) > 0 {
|
||||||
|
logger = logger.With("source", opportunities[0].Source)
|
||||||
|
}
|
||||||
|
|
||||||
filters := f.markSkipped(opportunities)
|
filters := f.markSkipped(opportunities)
|
||||||
|
|
||||||
result, err := f.store.SaveOpportunities(ctx, opportunities)
|
result, err := f.store.SaveOpportunities(ctx, opportunities)
|
||||||
|
|||||||
@@ -921,9 +921,12 @@ func TestSaveSkipsNewOpportunities(t *testing.T) {
|
|||||||
if !skipped(s) {
|
if !skipped(s) {
|
||||||
t.Error("a new matching opportunity wasn't skipped")
|
t.Error("a new matching opportunity wasn't skipped")
|
||||||
}
|
}
|
||||||
|
// Both lines name the source.
|
||||||
for _, want := range []string{
|
for _, want := range []string{
|
||||||
|
"msg=\"saved opportunities\" source=FindATender component=fetcher",
|
||||||
"skipped_opportunities=1",
|
"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) {
|
if !strings.Contains(logged.String(), want) {
|
||||||
t.Errorf("log has no %q:\n%s", want, logged.String())
|
t.Errorf("log has no %q:\n%s", want, logged.String())
|
||||||
|
|||||||
@@ -86,7 +86,11 @@ func fetchFindATender(
|
|||||||
return nil, ErrNoNewReleases
|
return nil, ErrNoNewReleases
|
||||||
}
|
}
|
||||||
|
|
||||||
tagged(logger).Info("fetched opportunities", "count", len(opportunities))
|
tagged(logger).Info(
|
||||||
|
"fetched opportunities",
|
||||||
|
"source", findATenderSource,
|
||||||
|
"count", len(opportunities),
|
||||||
|
)
|
||||||
|
|
||||||
return opportunities, err
|
return opportunities, err
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,11 @@ func fetchFTSMock(
|
|||||||
opportunity.Source = ftsMockSource
|
opportunity.Source = ftsMockSource
|
||||||
}
|
}
|
||||||
|
|
||||||
tagged(logger).Info("fetched opportunities", "count", len(opportunities))
|
tagged(logger).Info(
|
||||||
|
"fetched opportunities",
|
||||||
|
"source", ftsMockSource,
|
||||||
|
"count", len(opportunities),
|
||||||
|
)
|
||||||
|
|
||||||
return opportunities, err
|
return opportunities, err
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user