improve(search): progress & retries
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-12-01 17:02:53 -05:00
parent 3d61d0f5ef
commit 841b29c425
6 changed files with 256 additions and 231 deletions

22
search/progress.go Normal file
View File

@@ -0,0 +1,22 @@
package search
type writeCounter struct {
Total int64
Current int64
ProgressFunction func(float32)
}
func (wc *writeCounter) Write(p []byte) (int, error) {
n := len(p)
wc.Current += int64(n)
wc.flushProgress()
return n, nil
}
func (wc *writeCounter) flushProgress() {
if wc.ProgressFunction == nil || wc.Total < 100000 {
return
}
percentage := float32(wc.Current) * 100 / float32(wc.Total)
wc.ProgressFunction(percentage)
}