mirror of
https://git.sr.ht/~phw/scotty
synced 2025-06-05 04:58:33 +02:00
Pass context to export backends
This commit is contained in:
parent
b5bca1d4ab
commit
26d9f5e840
12 changed files with 55 additions and 33 deletions
|
@ -18,6 +18,7 @@ Scotty. If not, see <https://www.gnu.org/licenses/>.
|
|||
package spotifyhistory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -72,7 +73,7 @@ func (b *SpotifyHistoryBackend) InitConfig(config *config.ServiceConfig) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b *SpotifyHistoryBackend) ExportListens(oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
|
||||
func (b *SpotifyHistoryBackend) ExportListens(ctx context.Context, oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
|
||||
files, err := filepath.Glob(path.Join(b.dirPath, historyFileGlob))
|
||||
p := models.TransferProgress{
|
||||
Export: &models.Progress{},
|
||||
|
@ -89,11 +90,20 @@ func (b *SpotifyHistoryBackend) ExportListens(oldestTimestamp time.Time, results
|
|||
fileCount := int64(len(files))
|
||||
p.Export.Total = fileCount
|
||||
for i, filePath := range files {
|
||||
history, err := readHistoryFile(filePath)
|
||||
if err != nil {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
results <- models.ListensResult{Error: ctx.Err()}
|
||||
p.Export.Abort()
|
||||
progress <- p
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
history, err := readHistoryFile(filePath)
|
||||
if err != nil {
|
||||
results <- models.ListensResult{Error: err}
|
||||
p.Export.Abort()
|
||||
progress <- p
|
||||
return
|
||||
}
|
||||
listens := history.AsListenList(ListenListOptions{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue