try rill. run 'git pull' 10 at a time. most excellent
This commit is contained in:
parent
b34caae965
commit
02a5b213ae
80
checkout.go
80
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)
|
||||
}
|
||||
|
|
|
@ -119,11 +119,14 @@ func globalBuildOptions(vbox *gui.Node) {
|
|||
grid.NewButton("git pull", func() {
|
||||
me.Disable()
|
||||
defer me.Enable()
|
||||
rillGitPull()
|
||||
/*
|
||||
loop := me.repos.View.ReposSortByName()
|
||||
for loop.Scan() {
|
||||
repo := loop.Repo()
|
||||
repo.Run([]string{"git", "pull"})
|
||||
}
|
||||
*/
|
||||
})
|
||||
grid.NextRow()
|
||||
|
||||
|
|
Loading…
Reference in New Issue