mirror of
https://git.sr.ht/~phw/scotty
synced 2025-05-10 10:17:04 +02:00
Handle wait group for progress bar centrally
This does not need to be exposed and caller only needs to wait for the Progress instance.
This commit is contained in:
parent
d757129bd7
commit
16245e495d
2 changed files with 5 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>
|
Copyright © 2023-2025 Philipp Wolfer <phw@uploadedlobster.com>
|
||||||
|
|
||||||
This file is part of Scotty.
|
This file is part of Scotty.
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ import (
|
||||||
"go.uploadedlobster.com/scotty/internal/models"
|
"go.uploadedlobster.com/scotty/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func progressBar(wg *sync.WaitGroup, exportProgress chan models.Progress, importProgress chan models.Progress) *mpb.Progress {
|
func progressBar(exportProgress chan models.Progress, importProgress chan models.Progress) *mpb.Progress {
|
||||||
|
wg := &sync.WaitGroup{}
|
||||||
p := mpb.New(
|
p := mpb.New(
|
||||||
mpb.WithWaitGroup(wg),
|
mpb.WithWaitGroup(wg),
|
||||||
mpb.WithOutput(color.Output),
|
mpb.WithOutput(color.Output),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>
|
Copyright © 2023-2025 Philipp Wolfer <phw@uploadedlobster.com>
|
||||||
|
|
||||||
Scotty is free software: you can redistribute it and/or modify it under the
|
Scotty is free software: you can redistribute it and/or modify it under the
|
||||||
terms of the GNU General Public License as published by the Free Software
|
terms of the GNU General Public License as published by the Free Software
|
||||||
|
@ -19,7 +19,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -112,8 +111,7 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
|
||||||
// Prepare progress bars
|
// Prepare progress bars
|
||||||
exportProgress := make(chan models.Progress)
|
exportProgress := make(chan models.Progress)
|
||||||
importProgress := make(chan models.Progress)
|
importProgress := make(chan models.Progress)
|
||||||
var wg sync.WaitGroup
|
progress := progressBar(exportProgress, importProgress)
|
||||||
progress := progressBar(&wg, exportProgress, importProgress)
|
|
||||||
|
|
||||||
// Export from source
|
// Export from source
|
||||||
exportChan := make(chan R, 1000)
|
exportChan := make(chan R, 1000)
|
||||||
|
@ -126,7 +124,6 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
|
||||||
if timestamp.After(result.LastTimestamp) {
|
if timestamp.After(result.LastTimestamp) {
|
||||||
result.LastTimestamp = timestamp
|
result.LastTimestamp = timestamp
|
||||||
}
|
}
|
||||||
wg.Wait()
|
|
||||||
progress.Wait()
|
progress.Wait()
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
printTimestamp("Import failed, last reported timestamp was %v (%s)", result.LastTimestamp)
|
printTimestamp("Import failed, last reported timestamp was %v (%s)", result.LastTimestamp)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue