Add progress reporting to json_importer (#2494)

Fixes #2494
This commit is contained in:
Daniel Krech
2016-09-01 03:04:26 -04:00
committed by Aaron Boodman
parent 63f4127aac
commit 01bdeab025
2 changed files with 13 additions and 2 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ func (r *reader) Read(p []byte) (n int, err error) {
n, err = r.inner.Read(p)
r.seen += uint64(n)
if now := time.Now(); now.Sub(r.lastTime) >= status.Rate {
if now := time.Now(); now.Sub(r.lastTime) >= status.Rate || err == io.EOF {
r.cb(r.seen)
r.lastTime = now
}
+12 -1
View File
@@ -11,10 +11,14 @@ import (
"log"
"net/http"
"os"
"time"
"github.com/attic-labs/noms/go/d"
"github.com/attic-labs/noms/go/spec"
"github.com/attic-labs/noms/go/util/jsontonoms"
"github.com/attic-labs/noms/go/util/progressreader"
"github.com/attic-labs/noms/go/util/status"
"github.com/dustin/go-humanize"
flag "github.com/juju/gnuflag"
)
@@ -48,10 +52,17 @@ func main() {
defer res.Body.Close()
var jsonObject interface{}
err = json.NewDecoder(res.Body).Decode(&jsonObject)
start := time.Now()
r := progressreader.New(res.Body, func(seen uint64) {
elapsed := time.Since(start).Seconds()
rate := uint64(float64(seen) / elapsed)
status.Printf("%s decoded in %ds (%s/s)...", humanize.Bytes(seen), int(elapsed), humanize.Bytes(rate))
})
err = json.NewDecoder(r).Decode(&jsonObject)
if err != nil {
log.Fatalln("Error decoding JSON: ", err)
}
status.Done()
_, err = ds.CommitValue(jsontonoms.NomsValueFromDecodedJSON(jsonObject, true))
d.PanicIfError(err)