Make web service clients context aware

This commit is contained in:
Philipp Wolfer 2025-05-22 09:22:05 +02:00
parent adfe3f5771
commit d1642b7f1f
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
15 changed files with 128 additions and 76 deletions

View file

@ -16,6 +16,7 @@ Scotty. If not, see <https://www.gnu.org/licenses/>.
package deezer
import (
"context"
"fmt"
"math"
"net/url"
@ -78,6 +79,8 @@ func (b *DeezerApiBackend) OAuth2Setup(token oauth2.TokenSource) error {
}
func (b *DeezerApiBackend) ExportListens(oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
ctx := context.TODO()
// Choose a high offset, we attempt to search the loves backwards starting
// at the oldest one.
offset := math.MaxInt32
@ -96,7 +99,7 @@ func (b *DeezerApiBackend) ExportListens(oldestTimestamp time.Time, results chan
out:
for {
result, err := b.client.UserHistory(offset, perPage)
result, err := b.client.UserHistory(ctx, offset, perPage)
if err != nil {
p.Export.Abort()
progress <- p
@ -154,6 +157,8 @@ out:
}
func (b *DeezerApiBackend) ExportLoves(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.TransferProgress) {
ctx := context.TODO()
// Choose a high offset, we attempt to search the loves backwards starting
// at the oldest one.
offset := math.MaxInt32
@ -168,7 +173,7 @@ func (b *DeezerApiBackend) ExportLoves(oldestTimestamp time.Time, results chan m
out:
for {
result, err := b.client.UserTracks(offset, perPage)
result, err := b.client.UserTracks(ctx, offset, perPage)
if err != nil {
p.Export.Abort()
progress <- p