Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
Add feedback from review, not expected to pass until spec changes are
made
  • Loading branch information
michel-laterman committed Jan 20, 2025
1 parent 0a8d819 commit 6101559
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions client/internal/package_download_details_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,31 @@ func (p *downloadReporter) Write(b []byte) (int, error) {
// report periodically updates the package status details and calls the passed upateFn to send the new status.
func (p *downloadReporter) report(ctx context.Context, status *protobufs.PackageStatus, updateFn func(context.Context, bool) error) {
go func() {
timer := time.NewTimer(p.interval)
defer timer.Stop()
// Make sure we wait at least 1s before reporting the download rate in bps to avoid a panic
time.Sleep(time.Second)
ticker := time.NewTicker(p.interval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-p.done:
return
case <-timer.C:
case <-ticker.C:
downloadTime := time.Now().Sub(p.start)
downloaded := p.downloaded.Load()
bps := downloaded / uint64(downloadTime/time.Second)
downloaded := float64(p.downloaded.Load())
bps := downloaded / float64(downloadTime/time.Second)
var downloadPercent float64
if p.packageLength > 0 {
downloadPercent = float64(downloaded) / float64(p.packageLength) * 100
downloadPercent = downloaded / p.packageLength * 100
}
status.DownloadDetails = &protobufs.PackageDownloadDetails{
DownloadPercent: downloadPercent,
// DownloadPercent may be zero if nothing has been downloaded OR there isn't a Content-Length header in the response.
DownloadPercent: downloadPercent,
// DownloadBytesPerSecond may be zero if no bytes from the response body have been read yet.
DownloadBytesPerSecond: bps,

Check failure on line 67 in client/internal/package_download_details_reporter.go

View workflow job for this annotation

GitHub Actions / build-and-test

cannot use bps (variable of type float64) as uint64 value in struct literal

Check failure on line 67 in client/internal/package_download_details_reporter.go

View workflow job for this annotation

GitHub Actions / test-coverage

cannot use bps (variable of type float64) as uint64 value in struct literal
}
_ = updateFn(ctx, true)
timer.Reset(p.interval)
}
}
}()
Expand Down

0 comments on commit 6101559

Please sign in to comment.