summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.go24
-rw-r--r--rill.go63
2 files changed, 66 insertions, 21 deletions
diff --git a/init.go b/init.go
index 4cbaa16..78b3ae5 100644
--- a/init.go
+++ b/init.go
@@ -34,7 +34,8 @@ func Init() *Forge {
log.Info("forgepb.Scan() Scan found", end-start, "new git repositories. Total =", end)
}
- f.updateAll()
+ f.rillUpdate(20, 10)
+ // f.updateAll()
if f.configSave {
f.ConfigSave()
@@ -49,26 +50,7 @@ func (f *Forge) updateAll() {
for all.Scan() {
repo := all.Next()
- if !repo.IsValidDir() {
- log.Printf("%10s %-50s", "bad git dir\n", repo.FullPath)
- f.Repos.DeleteByFullPath(repo.FullPath)
- f.configSave = true
- continue
- }
-
- if repo.RepoChanged() {
- f.configSave = true
- log.Info("repo changed", repo.StateChange, repo.FullPath)
- repo.Reload()
- }
- if f.Config.IsReadOnly(repo.GetGoPath()) {
- if repo.ReadOnly {
- } else {
- log.Info("readonly flag on repo is wrong", repo.GetGoPath())
- repo.ReadOnly = true
- f.configSave = true
- }
- }
+ f.updateRepo(repo)
}
}
diff --git a/rill.go b/rill.go
new file mode 100644
index 0000000..4876aa7
--- /dev/null
+++ b/rill.go
@@ -0,0 +1,63 @@
+package forgepb
+
+import (
+ "github.com/destel/rill"
+ "go.wit.com/lib/protobuf/gitpb"
+ "go.wit.com/log"
+)
+
+// rill is awesome. long live rill
+// attempt scan with rill
+func (f *Forge) rillUpdate(pool1 int, pool2 int) (int, error) {
+ var repos []*gitpb.Repo
+ all := f.Repos.SortByFullPath()
+ for all.Scan() {
+ repo := all.Next()
+ repos = append(repos, repo)
+ }
+
+ // Convert a slice of user IDs into a channel
+ ids := rill.FromSlice(repos, nil)
+
+ // Read users from the API.
+ // Concurrency = 20
+ rills := rill.Map(ids, pool1, func(repo *gitpb.Repo) (*gitpb.Repo, error) {
+ return repo, nil
+ })
+
+ var counter int
+ // Activate users.
+ // Concurrency = 10
+ err := rill.ForEach(rills, pool2, func(repo *gitpb.Repo) error {
+ counter += 1
+ return f.updateRepo(repo)
+ })
+
+ return counter, err
+}
+
+func (f *Forge) updateRepo(repo *gitpb.Repo) error {
+ if !repo.IsValidDir() {
+ log.Printf("%10s %-50s", "bad git dir\n", repo.FullPath)
+ f.Repos.DeleteByFullPath(repo.FullPath)
+ f.configSave = true
+ return nil
+ }
+
+ if repo.DidRepoChange() {
+ f.configSave = true
+ log.Info("repo changed", repo.StateChange, repo.FullPath)
+ if err := repo.Reload(); err != nil {
+ return err
+ }
+ }
+ if f.Config.IsReadOnly(repo.GetGoPath()) {
+ if repo.ReadOnly {
+ } else {
+ log.Info("readonly flag on repo is wrong", repo.GetGoPath())
+ repo.ReadOnly = true
+ f.configSave = true
+ }
+ }
+ return nil
+}