[arvados-dev] updated: e96a5d05a560d306f61eedbf7362c2d6957893db

git repository hosting git at public.arvados.org
Wed Jan 25 21:31:44 UTC 2023


Summary of changes:
 cmd/art/redmine.go | 85 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 76 insertions(+), 9 deletions(-)

       via  e96a5d05a560d306f61eedbf7362c2d6957893db (commit)
      from  87dcb0fae25b06b9ded592b55084fb5a4cdba8fc (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit e96a5d05a560d306f61eedbf7362c2d6957893db
Author: Lucas Di Pentima <lucas at di-pentima.com.ar>
Date:   Wed Jan 25 18:29:47 2023 -0300

    Adds worker pool to speed up processing lots of issues. Refs #19920
    
    The single-threaded version was processing issues at about 1 per second,
    too slow to move lots of issues in one go.
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima at curii.com>

diff --git a/cmd/art/redmine.go b/cmd/art/redmine.go
index abeded3..1ad293b 100644
--- a/cmd/art/redmine.go
+++ b/cmd/art/redmine.go
@@ -13,6 +13,7 @@ import (
 	"regexp"
 	"sort"
 	"strconv"
+	"sync"
 	"time"
 
 	"git.arvados.org/arvados-dev.git/lib/redmine"
@@ -182,18 +183,84 @@ var associateOrphans = &cobra.Command{
 			fmt.Printf("Error requesting unassigned open issues from project %d: %s", p.ID, err)
 		}
 		fmt.Printf("Found %d issues from project '%s' to assign to release '%s'...\n", len(issues), p.Name, r.Name)
+
+		type job struct {
+			issue  redmine.Issue
+			rID    int
+			dryRun bool
+		}
+		type result struct {
+			msg     string
+			success bool
+		}
+		var wg sync.WaitGroup
+		jobs := make(chan job, len(issues))
+		results := make(chan result, len(issues))
+
+		worker := func(id int, jobs <-chan job, results chan<- result) {
+			for j := range jobs {
+				msg := fmt.Sprintf("#%d - %s ", j.issue.ID, j.issue.Subject)
+				success := true
+				if !j.dryRun {
+					err = rm.SetRelease(j.issue, j.rID)
+					if err != nil {
+						success = false
+						msg = fmt.Sprintf("%s [error] (%s)\n", msg, err)
+					} else {
+						msg = fmt.Sprintf("%s [changed]\n", msg)
+					}
+				} else {
+					msg = fmt.Sprintf("%s [skipped]\n", msg)
+				}
+				results <- result{
+					msg:     msg,
+					success: success,
+				}
+			}
+		}
+
+		wn := 8
+		if len(issues) < wn {
+			wn = len(issues)
+		}
+		for w := 1; w <= wn; w++ {
+			wg.Add(1)
+			w := w
+			go func() {
+				defer wg.Done()
+				worker(w, jobs, results)
+			}()
+		}
+
 		for _, issue := range issues {
-			fmt.Printf("#%d - %s ", issue.ID, issue.Subject)
-			if !dryRun {
-				err = rm.SetRelease(issue, rID)
-				if err != nil {
-					fmt.Printf("[error]\n")
-					log.Fatalf("Error trying to assign issue %d to release %d: %s", issue.ID, rID, err)
+			jobs <- job{
+				issue:  issue,
+				rID:    rID,
+				dryRun: dryRun,
+			}
+		}
+		close(jobs)
+
+		succeded := true
+		errCount := 0
+		var wg2 sync.WaitGroup
+		wg2.Add(1)
+		go func() {
+			defer wg2.Done()
+			for r := range results {
+				fmt.Printf(r.msg)
+				if !r.success {
+					succeded = false
+					errCount += 1
 				}
-				fmt.Printf("[changed]\n")
-			} else {
-				fmt.Printf("[skipped]\n")
 			}
+		}()
+
+		wg.Wait()
+		close(results)
+		wg2.Wait()
+		if !succeded {
+			log.Fatalf("Warning: %d error(s) found.", errCount)
 		}
 	},
 }

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list