From 02a5b213aebf5711373e75d6e3255b764f3bc747 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 26 Nov 2024 03:15:38 -0600 Subject: [PATCH] try rill. run 'git pull' 10 at a time. most excellent --- checkout.go | 80 +++++++++++++++++++++++++++++++++++++++++++ globalBuildOptions.go | 13 ++++--- 2 files changed, 88 insertions(+), 5 deletions(-) diff --git a/checkout.go b/checkout.go index 3b18b89..0a082bb 100644 --- a/checkout.go +++ b/checkout.go @@ -6,6 +6,13 @@ package main */ import ( + "context" + "fmt" + + "github.com/destel/rill" + "github.com/destel/rill/mockapi" + + "go.wit.com/lib/gui/repolist" "go.wit.com/log" ) @@ -32,3 +39,76 @@ func checkoutDevel() bool { log.Info("Ran git checkout in", count, "repos. failure count =", failed) return true } + +// https://news.ycombinator.com/item?id=42237166 +// https://github.com/destel/rill +// https://pkg.go.dev/github.com/destel/rill +func rillMockapi() { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + // Convert a slice of user IDs into a channel + ids := rill.FromSlice([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, nil) + + // Read users from the API. + // Concurrency = 3 + users := rill.Map(ids, 3, func(id int) (*mockapi.User, error) { + return mockapi.GetUser(ctx, id) + }) + + // Activate users. + // Concurrency = 2 + err := rill.ForEach(users, 2, func(u *mockapi.User) error { + if u.IsActive { + fmt.Printf("User %d is already active\n", u.ID) + return nil + } + + u.IsActive = true + err := mockapi.SaveUser(ctx, u) + if err != nil { + return err + } + + fmt.Printf("User saved: %+v\n", u) + return nil + }) + + // Handle errors + fmt.Println("Error:", err) +} + +// rediculously wrong for the purposes of understanding rill +// which, seems to be awesome. long live rill +func rillGitPull() { + // todo: wrap my head around what this could be for + // ctx, cancel := context.WithCancel(context.Background()) + // defer cancel() + + var gopaths []string + loop := me.repos.View.ReposSortByName() + for loop.Scan() { + repo := loop.Repo() + gopaths = append(gopaths, repo.GoPath()) + } + + // Convert a slice of user IDs into a channel + ids := rill.FromSlice(gopaths, nil) + + // Read users from the API. + // Concurrency = 20 + users := rill.Map(ids, 20, func(id string) (*repolist.RepoRow, error) { + return me.repos.View.FindByName(id), nil + }) + + // Activate users. + // Concurrency = 10 + err := rill.ForEach(users, 10, func(repo *repolist.RepoRow) error { + fmt.Printf("Repo found : %s\n", repo.GoPath()) + repo.Run([]string{"git", "pull"}) + return nil + }) + + // Handle errors + fmt.Println("Error:", err) +} diff --git a/globalBuildOptions.go b/globalBuildOptions.go index b3e1fae..95c8a14 100644 --- a/globalBuildOptions.go +++ b/globalBuildOptions.go @@ -119,11 +119,14 @@ func globalBuildOptions(vbox *gui.Node) { grid.NewButton("git pull", func() { me.Disable() defer me.Enable() - loop := me.repos.View.ReposSortByName() - for loop.Scan() { - repo := loop.Repo() - repo.Run([]string{"git", "pull"}) - } + rillGitPull() + /* + loop := me.repos.View.ReposSortByName() + for loop.Scan() { + repo := loop.Repo() + repo.Run([]string{"git", "pull"}) + } + */ }) grid.NextRow()