feat: throttle variable for imports

This commit is contained in:
Gabe Farrell 2025-06-11 22:40:36 -04:00
parent 20cc4ce27a
commit f7621d0383
3 changed files with 24 additions and 0 deletions

View file

@ -39,6 +39,12 @@ func ImportMalojaFile(ctx context.Context, store db.DB, filename string) error {
l.Err(err).Msgf("Failed to read import file: %s", filename)
return err
}
var throttleFunc = func() {}
if ms := cfg.ThrottleImportMs(); ms > 0 {
throttleFunc = func() {
time.Sleep(time.Duration(ms) * time.Millisecond)
}
}
export := new(MalojaExport)
err = json.NewDecoder(file).Decode(&export)
if err != nil {
@ -73,6 +79,7 @@ func ImportMalojaFile(ctx context.Context, store db.DB, filename string) error {
l.Err(err).Msg("Failed to import maloja playback item")
return err
}
throttleFunc()
}
_, err = os.Stat(path.Join(cfg.ConfigDir(), "import_complete"))
if err != nil {

View file

@ -31,6 +31,12 @@ func ImportSpotifyFile(ctx context.Context, store db.DB, filename string) error
l.Err(err).Msgf("Failed to read import file: %s", filename)
return err
}
var throttleFunc = func() {}
if ms := cfg.ThrottleImportMs(); ms > 0 {
throttleFunc = func() {
time.Sleep(time.Duration(ms) * time.Millisecond)
}
}
export := make([]SpotifyExportItem, 0)
err = json.NewDecoder(file).Decode(&export)
if err != nil {
@ -59,6 +65,7 @@ func ImportSpotifyFile(ctx context.Context, store db.DB, filename string) error
l.Err(err).Msg("Failed to import spotify playback item")
return err
}
throttleFunc()
}
_, err = os.Stat(path.Join(cfg.ConfigDir(), "import_complete"))
if err != nil {