mirror of
https://git.sr.ht/~phw/scotty
synced 2025-06-05 12:58:33 +02:00
Make web service clients context aware
This commit is contained in:
parent
adfe3f5771
commit
d1642b7f1f
15 changed files with 128 additions and 76 deletions
|
@ -17,6 +17,7 @@ Scotty. If not, see <https://www.gnu.org/licenses/>.
|
|||
package maloja
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -64,6 +65,7 @@ func (b *MalojaApiBackend) StartImport() error { return nil }
|
|||
func (b *MalojaApiBackend) FinishImport() error { return nil }
|
||||
|
||||
func (b *MalojaApiBackend) ExportListens(oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
|
||||
ctx := context.TODO()
|
||||
page := 0
|
||||
perPage := MaxItemsPerGet
|
||||
|
||||
|
@ -77,7 +79,7 @@ func (b *MalojaApiBackend) ExportListens(oldestTimestamp time.Time, results chan
|
|||
|
||||
out:
|
||||
for {
|
||||
result, err := b.client.GetScrobbles(page, perPage)
|
||||
result, err := b.client.GetScrobbles(ctx, page, perPage)
|
||||
if err != nil {
|
||||
p.Export.Abort()
|
||||
progress <- p
|
||||
|
@ -112,6 +114,8 @@ out:
|
|||
}
|
||||
|
||||
func (b *MalojaApiBackend) ImportListens(export models.ListensResult, importResult models.ImportResult, progress chan models.TransferProgress) (models.ImportResult, error) {
|
||||
ctx := context.TODO()
|
||||
|
||||
p := models.TransferProgress{}.FromImportResult(importResult, false)
|
||||
for _, listen := range export.Items {
|
||||
scrobble := NewScrobble{
|
||||
|
@ -124,7 +128,7 @@ func (b *MalojaApiBackend) ImportListens(export models.ListensResult, importResu
|
|||
Nofix: b.nofix,
|
||||
}
|
||||
|
||||
resp, err := b.client.NewScrobble(scrobble)
|
||||
resp, err := b.client.NewScrobble(ctx, scrobble)
|
||||
if err != nil {
|
||||
return importResult, err
|
||||
} else if resp.Status != "success" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue