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
|
@ -23,6 +23,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -60,15 +61,25 @@ var listensCmd = &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
|
||||
listens := make(chan models.ListensResult, 1000)
|
||||
go exportBackend.ExportListens(timestamp, listens)
|
||||
listensChan := make(chan models.ListensResult, 1000)
|
||||
go exportBackend.ExportListens(timestamp, listensChan, exportProgress)
|
||||
|
||||
// Import into target
|
||||
result, err := importBackend.ImportListens(listens, timestamp)
|
||||
if err != nil {
|
||||
resultChan := make(chan models.ImportResult)
|
||||
go backends.ProcessListensImports(importBackend, listensChan, 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(err)
|
||||
cobra.CheckErr(result.Error)
|
||||
}
|
||||
fmt.Printf("Imported %v of %v listens into %v.\n",
|
||||
result.ImportCount, result.TotalCount, targetName)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue