Skip to content

Commit

Permalink
Merge pull request #183 from grisu48/revtui
Browse files Browse the repository at this point in the history
Add progress for jobs fetch
  • Loading branch information
grisu48 authored Dec 16, 2024
2 parents de46fe9 + 622ff71 commit 4f65f2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cmd/openqa-revtui/openqa-revtui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 7 additions & 2 deletions cmd/openqa-revtui/openqa.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f65f2d

Please sign in to comment.