Added a backfill in 7-day windows, and fetches now keep their data on a failure

Backfilling a long window (an early --since, or a long time offline)
hit the API's rate limit, which could still be exceeded after waiting
once, and then everything fetched so far was lost.

Before each Find a Tender source's worker starts, a start point more
than 7 days ago is now backfilled in 7-day windows bounded on both
sides, oldest first, each saved before the next is fetched. A window
that fails is saved as far as it got and fetched again from its start
after the source's interval. The worker then carries on from the end
of the last window.

A 429 is now waited out up to sources.<source>.rate_limit_retries
times (default 5) rather than once; fts-once --ignore-rate-limit uses
0. FetchAll returns what it fetched before an error along with it, and
the workers save it, so a failed run no longer loses its data.
findatender's FetchAll and FetchOnce take RequestOptions, which gains
Until (updatedTo), and RateLimitRetries replaces AllowRateLimit.
This commit is contained in:
bwilliams committed 2026-10-21 12:40:39 +01:00
1 parent ff2aa316b5
commit c09c30ae71
16 files changed
+683 -149

No files matched your search

+24 -2
View File
@@ -56,6 +56,14 @@ func TestDefaults(t *testing.T) {
if conf.Sources.FTSMock.APIRoot != "" {
t.Errorf("FTSMock.APIRoot = %q; want empty", conf.Sources.FTSMock.APIRoot)
}
if conf.Sources.FindATender.RateLimitRetries != 5 ||
conf.Sources.FTSMock.RateLimitRetries != 5 {
t.Errorf(
"RateLimitRetries = %d, %d; want 5, 5",
conf.Sources.FindATender.RateLimitRetries,
conf.Sources.FTSMock.RateLimitRetries,
)
}
for name, src := range map[string]JSCSourcesSource{
"find_a_tender": conf.Sources.FindATender.JSCSourcesSource,
"fts_mock": conf.Sources.FTSMock.JSCSourcesSource,
@@ -236,6 +244,20 @@ func TestConcreteSourceSections(t *testing.T) {
}
wantMap["api_root"] = "http://localhost:8080"
wantFlat[tt.prefix+".api_root"] = "http://localhost:8080"
// The Find a Tender sources' own validate must still check
// interval, as JSCSourcesSource's does.
if err := s.SetValue("rate_limit_retries", "3"); err != nil {
t.Fatalf("SetValue(rate_limit_retries): %v", err)
}
if err := s.SetValue("rate_limit_retries", "-1"); err == nil {
t.Error("SetValue(rate_limit_retries, -1) succeeded")
}
if err := s.SetValue("interval", "0s"); err == nil {
t.Error("SetValue(interval, 0s) succeeded")
}
wantMap["rate_limit_retries"] = 3
wantFlat[tt.prefix+".rate_limit_retries"] = 3
} else if _, err := s.TypeOf("api_root"); err == nil {
t.Error("TypeOf(api_root) succeeded on a source without one")
}
@@ -295,8 +317,8 @@ func TestSourcesSection(t *testing.T) {
if flat["sources.fts_mock.api_root"] != "http://mock" {
t.Errorf("Flatten missing sources.fts_mock.api_root: %v", flat)
}
if len(flat) != 10 {
t.Errorf("Flatten has %d keys; want 10: %v", len(flat), flat)
if len(flat) != 12 {
t.Errorf("Flatten has %d keys; want 12: %v", len(flat), flat)
}
if err := c.SetValue("skip_rules_file", "rules.json"); err != nil ||