mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-28 06:57:56 +02:00
Implemented progressbar for export/import
This commit is contained in:
parent
ab04eb1123
commit
6e330daf06
24 changed files with 590 additions and 239 deletions
22
cmd/loves.go
22
cmd/loves.go
|
@ -23,6 +23,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -60,13 +61,26 @@ var lovesCmd = &cobra.Command{
|
|||
}
|
||||
fmt.Printf("From timestamp: %v (%v)\n", timestamp, timestamp.Unix())
|
||||
|
||||
// Prepare progress bars
|
||||
exportProgress := make(chan models.Progress)
|
||||
importProgress := make(chan models.Progress)
|
||||
var wg sync.WaitGroup
|
||||
progress := progressBar(&wg, exportProgress, importProgress)
|
||||
|
||||
// Export from source
|
||||
loves := make(chan models.LovesResult, 1000)
|
||||
go exportBackend.ExportLoves(timestamp, loves)
|
||||
lovesChan := make(chan models.LovesResult, 1000)
|
||||
go exportBackend.ExportLoves(timestamp, lovesChan, exportProgress)
|
||||
|
||||
// Import into target
|
||||
result, err := importBackend.ImportLoves(loves, timestamp)
|
||||
cobra.CheckErr(err)
|
||||
resultChan := make(chan models.ImportResult)
|
||||
go backends.ProcessLovesImports(importBackend, lovesChan, resultChan, importProgress)
|
||||
result := <-resultChan
|
||||
wg.Wait()
|
||||
progress.Wait()
|
||||
if result.Error != nil {
|
||||
fmt.Printf("Import failed, last reported timestamp was %v (%v)\n", result.LastTimestamp, result.LastTimestamp.Unix())
|
||||
cobra.CheckErr(result.Error)
|
||||
}
|
||||
fmt.Printf("Imported %v of %v loves into %v.\n",
|
||||
result.ImportCount, result.TotalCount, targetName)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue