diff --git a/cmd/openqa-revtui/openqa-revtui.go b/cmd/openqa-revtui/openqa-revtui.go index f95c4c3..c5bb10c 100644 --- a/cmd/openqa-revtui/openqa-revtui.go +++ b/cmd/openqa-revtui/openqa-revtui.go @@ -231,7 +231,11 @@ func refreshJobs(tui *TUI, instance *gopenqa.Instance) error { for _, job := range oldJobs { ids = append(ids, job.ID) } - jobs, err := fetchJobsFollow(ids, instance) + callback := func(i, n int) { + tui.SetStatus(fmt.Sprintf("Refreshing %d jobs ... %d%% ", len(oldJobs), 100/n*i)) + tui.Update() + } + jobs, err := fetchJobsFollow(ids, instance, callback) if err != nil { return err } diff --git a/cmd/openqa-revtui/openqa.go b/cmd/openqa-revtui/openqa.go index 068cfb5..4fd9fef 100644 --- a/cmd/openqa-revtui/openqa.go +++ b/cmd/openqa-revtui/openqa.go @@ -108,13 +108,18 @@ func FetchJob(id int64, instance *gopenqa.Instance) (gopenqa.Job, error) { } /* Fetch the given jobs and follow their clones */ -func fetchJobsFollow(ids []int64, instance *gopenqa.Instance) ([]gopenqa.Job, error) { +func fetchJobsFollow(ids []int64, instance *gopenqa.Instance, progress func(i, n int)) ([]gopenqa.Job, error) { // Obey the maximum number of job per requests. // We split the job ids into multiple requests if necessary jobs := make([]gopenqa.Job, 0) - for len(ids) > 0 { + // Progress variables + chunks := len(ids) / cf.RequestJobLimit + for i := 0; len(ids) > 0; i++ { // Repeat until no more ids are available. n := min(cf.RequestJobLimit, len(ids)) chunk, err := instance.GetJobsFollow(ids[:n]) + if progress != nil { + progress(i, chunks) + } ids = ids[n:] if err != nil { return jobs, err