mirror of
https://git.sr.ht/~phw/scotty
synced 2025-05-09 18:07:03 +02:00
If import fails still save the last reported timestamp
This allows continuing a partially failed import run.
This commit is contained in:
parent
069f0de2ee
commit
55ac41b147
3 changed files with 15 additions and 15 deletions
|
@ -51,7 +51,7 @@ func (p ListensImportProcessor) Import(export models.ListensResult, result model
|
|||
}
|
||||
importResult, err := p.Backend.ImportListens(export, result, progress)
|
||||
if err != nil {
|
||||
return result, err
|
||||
return importResult, err
|
||||
}
|
||||
return importResult, nil
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func (p LovesImportProcessor) Import(export models.LovesResult, result models.Im
|
|||
}
|
||||
importResult, err := p.Backend.ImportLoves(export, result, progress)
|
||||
if err != nil {
|
||||
return result, err
|
||||
return importResult, err
|
||||
}
|
||||
return importResult, nil
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ func process[R models.LovesResult | models.ListensResult, P ImportProcessor[R]](
|
|||
defer close(out)
|
||||
defer close(progress)
|
||||
result := models.ImportResult{}
|
||||
p := models.Progress{}
|
||||
|
||||
if err := processor.ImportBackend().StartImport(); err != nil {
|
||||
out <- handleError(result, err, progress)
|
||||
|
@ -97,13 +98,13 @@ func process[R models.LovesResult | models.ListensResult, P ImportProcessor[R]](
|
|||
|
||||
for exportResult := range results {
|
||||
importResult, err := processor.Import(exportResult, result, out, progress)
|
||||
result.Update(importResult)
|
||||
if err != nil {
|
||||
processor.ImportBackend().FinishImport()
|
||||
out <- handleError(result, err, progress)
|
||||
return
|
||||
}
|
||||
result.Update(importResult)
|
||||
progress <- models.Progress{}.FromImportResult(result)
|
||||
progress <- p.FromImportResult(result)
|
||||
}
|
||||
|
||||
if err := processor.ImportBackend().FinishImport(); err != nil {
|
||||
|
@ -111,7 +112,7 @@ func process[R models.LovesResult | models.ListensResult, P ImportProcessor[R]](
|
|||
return
|
||||
}
|
||||
|
||||
progress <- models.Progress{}.FromImportResult(result).Complete()
|
||||
progress <- p.FromImportResult(result).Complete()
|
||||
out <- result
|
||||
}
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ out:
|
|||
}
|
||||
|
||||
func (b *MalojaApiBackend) ImportListens(export models.ListensResult, importResult models.ImportResult, progress chan models.Progress) (models.ImportResult, error) {
|
||||
p := models.Progress{}.FromImportResult(importResult)
|
||||
for _, listen := range export.Items {
|
||||
scrobble := NewScrobble{
|
||||
Title: listen.TrackName,
|
||||
|
@ -125,7 +126,7 @@ func (b *MalojaApiBackend) ImportListens(export models.ListensResult, importResu
|
|||
|
||||
importResult.UpdateTimestamp(listen.ListenedAt)
|
||||
importResult.ImportCount += 1
|
||||
progress <- models.Progress{}.FromImportResult(importResult)
|
||||
progress <- p.FromImportResult(importResult)
|
||||
}
|
||||
|
||||
return importResult, nil
|
||||
|
|
|
@ -121,16 +121,7 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
|
|||
resultChan := make(chan models.ImportResult)
|
||||
go imp.Process(exportChan, resultChan, importProgress)
|
||||
result := <-resultChan
|
||||
if timestamp.After(result.LastTimestamp) {
|
||||
result.LastTimestamp = timestamp
|
||||
}
|
||||
progress.Wait()
|
||||
if result.Error != nil {
|
||||
printTimestamp("Import failed, last reported timestamp was %v (%s)", result.LastTimestamp)
|
||||
return result.Error
|
||||
}
|
||||
fmt.Println(i18n.Tr("Imported %v of %v %s into %v.",
|
||||
result.ImportCount, result.TotalCount, c.entity, c.targetName))
|
||||
|
||||
// Update timestamp
|
||||
err = c.updateTimestamp(result, timestamp)
|
||||
|
@ -138,6 +129,13 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Println(i18n.Tr("Imported %v of %v %s into %v.",
|
||||
result.ImportCount, result.TotalCount, c.entity, c.targetName))
|
||||
if result.Error != nil {
|
||||
printTimestamp("Import failed, last reported timestamp was %v (%s)", result.LastTimestamp)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
// Print errors
|
||||
if len(result.ImportLog) > 0 {
|
||||
fmt.Println()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue