diff --git a/internal/extsvc/lotw.go b/internal/extsvc/lotw.go index 7bf62c3..4e8cc23 100644 --- a/internal/extsvc/lotw.go +++ b/internal/extsvc/lotw.go @@ -50,7 +50,7 @@ func readWithProgress(ctx context.Context, r io.Reader, note func(string)) ([]by total int64 last = time.Now() buf = make([]byte, 64*1024) - next = int64(1024 * 1024) // first report at 1 MB + next = int64(256 * 1024) // first report early — proof it is moving ) for { if err := ctx.Err(); err != nil { @@ -63,7 +63,7 @@ func readWithProgress(ctx context.Context, r io.Reader, note func(string)) ([]by last = time.Now() if total >= next { say(note, fmt.Sprintf(" … %.1f MB received", float64(total)/(1024*1024))) - next = total + 1024*1024 + next = total + 512*1024 } if total >= lotwMaxBytes { return out, nil @@ -142,6 +142,28 @@ func DownloadLoTWConfirmations(ctx context.Context, client *http.Client, cfg Ser // again. Three tries, spaced, and each one said out loud: an operator whose // download takes four minutes because the ARRL is loaded should be able to // see that rather than guess it. + // LoTW sends nothing at all until the whole report is built — minutes for a + // large account. That silence was the entire complaint: a window saying + // "working" with no way to tell a busy server from a dead one. Count it out + // loud until the first byte. + beat := make(chan struct{}) + go func() { + start := time.Now() + tick := time.NewTicker(15 * time.Second) + defer tick.Stop() + for { + select { + case <-beat: + return + case <-ctx.Done(): + return + case <-tick.C: + say(note, fmt.Sprintf(" … still waiting for LoTW to build the report (%.0f s)", time.Since(start).Seconds())) + } + } + }() + defer close(beat) + var resp *http.Response for attempt := 1; ; attempt++ { resp, err = client.Do(req) //nolint:bodyclose // closed below or in the retry @@ -170,6 +192,7 @@ func DownloadLoTWConfirmations(ctx context.Context, client *http.Client, cfg Ser return "", fmt.Errorf("lotw: request failed: %w", err) } defer resp.Body.Close() + say(note, fmt.Sprintf("LoTW answered (HTTP %d) — receiving…", resp.StatusCode)) body, err := readWithProgress(ctx, resp.Body, note) if err != nil { return "", fmt.Errorf("lotw: read response: %w", err)