Add a nice progress bar
This commit is contained in:
+9
-1
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/migrate/types"
|
||||
sysRepo "github.com/cortezaproject/corteza-server/system/repository"
|
||||
sysTypes "github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/schollz/progressbar/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -214,9 +215,16 @@ func (m *Migrator) MakeAcyclic() {
|
||||
|
||||
// processess migration nodes and migrates the data from the provided source files
|
||||
func (m *Migrator) Migrate(ctx context.Context, users map[string]uint64) error {
|
||||
fmt.Println("(•_•)")
|
||||
fmt.Println("(-•_•)>⌐■-■")
|
||||
fmt.Println("(⌐■_■)")
|
||||
fmt.Print("\n\n\n")
|
||||
|
||||
db := repository.DB(ctx)
|
||||
repoRecord := repository.Record(ctx, db)
|
||||
|
||||
bar := progressbar.New(len(m.nodes))
|
||||
|
||||
return db.Transaction(func() (err error) {
|
||||
for len(m.Leafs) > 0 {
|
||||
var wg sync.WaitGroup
|
||||
@@ -226,7 +234,7 @@ func (m *Migrator) Migrate(ctx context.Context, users map[string]uint64) error {
|
||||
wg.Add(1)
|
||||
|
||||
// migrate & update leaf nodes
|
||||
go n.Migrate(repoRecord, users, &wg, ch)
|
||||
go n.Migrate(repoRecord, users, &wg, ch, bar)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
@@ -76,8 +76,9 @@ func (n *Node) addMap(key string, m Map) {
|
||||
}
|
||||
|
||||
// does the actual data migration for the given node
|
||||
func (n *Node) Migrate(repoRecord repository.RecordRepository, users map[string]uint64, wg *sync.WaitGroup, ch chan PostProc) {
|
||||
func (n *Node) Migrate(repoRecord repository.RecordRepository, users map[string]uint64, wg *sync.WaitGroup, ch chan PostProc, bar *progressbar.ProgressBar) {
|
||||
defer wg.Done()
|
||||
defer bar.Add(1)
|
||||
|
||||
fmt.Printf("node.migrate > %s\n", n.Stringify())
|
||||
var err error
|
||||
|
||||
Reference in New Issue
Block a user