fix(lotw): count out the wait before the first byte
The progress lines only start once bytes arrive, and on a large account nothing arrives for minutes — LoTW builds the entire report before sending any of it. That silence WAS the complaint: the window still just said 'working'. A heartbeat every fifteen seconds until the headers land, then the HTTP status, then the megabytes — the first at 256 KB rather than 1 MB, so the very first sign that it is moving comes early.
This commit is contained in:
+25
-2
@@ -50,7 +50,7 @@ func readWithProgress(ctx context.Context, r io.Reader, note func(string)) ([]by
|
|||||||
total int64
|
total int64
|
||||||
last = time.Now()
|
last = time.Now()
|
||||||
buf = make([]byte, 64*1024)
|
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 {
|
for {
|
||||||
if err := ctx.Err(); err != nil {
|
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()
|
last = time.Now()
|
||||||
if total >= next {
|
if total >= next {
|
||||||
say(note, fmt.Sprintf(" … %.1f MB received", float64(total)/(1024*1024)))
|
say(note, fmt.Sprintf(" … %.1f MB received", float64(total)/(1024*1024)))
|
||||||
next = total + 1024*1024
|
next = total + 512*1024
|
||||||
}
|
}
|
||||||
if total >= lotwMaxBytes {
|
if total >= lotwMaxBytes {
|
||||||
return out, nil
|
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
|
// 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
|
// download takes four minutes because the ARRL is loaded should be able to
|
||||||
// see that rather than guess it.
|
// 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
|
var resp *http.Response
|
||||||
for attempt := 1; ; attempt++ {
|
for attempt := 1; ; attempt++ {
|
||||||
resp, err = client.Do(req) //nolint:bodyclose // closed below or in the retry
|
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)
|
return "", fmt.Errorf("lotw: request failed: %w", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
say(note, fmt.Sprintf("LoTW answered (HTTP %d) — receiving…", resp.StatusCode))
|
||||||
body, err := readWithProgress(ctx, resp.Body, note)
|
body, err := readWithProgress(ctx, resp.Body, note)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("lotw: read response: %w", err)
|
return "", fmt.Errorf("lotw: read response: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user