mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 21:57:06 +02:00
Run exporter in goroutine
Use channel to pass data from exporter to importer
This commit is contained in:
parent
1ba165a631
commit
298697dcfc
7 changed files with 124 additions and 42 deletions
|
@ -35,36 +35,50 @@ func (b DumpBackend) FromConfig(config *viper.Viper) models.Backend {
|
|||
return b
|
||||
}
|
||||
|
||||
func (b DumpBackend) ImportListens(listens []models.Listen, oldestTimestamp time.Time) (models.ImportResult, error) {
|
||||
result := models.ImportResult{
|
||||
TotalCount: len(listens),
|
||||
func (b DumpBackend) ImportListens(results chan models.ListensResult, oldestTimestamp time.Time) (models.ImportResult, error) {
|
||||
importResult := models.ImportResult{
|
||||
TotalCount: 0,
|
||||
ImportCount: 0,
|
||||
LastTimestamp: oldestTimestamp,
|
||||
}
|
||||
for _, listen := range listens {
|
||||
if listen.ListenedAt.Unix() > result.LastTimestamp.Unix() {
|
||||
result.LastTimestamp = listen.ListenedAt
|
||||
for result := range results {
|
||||
if result.Error != nil {
|
||||
return importResult, result.Error
|
||||
}
|
||||
|
||||
importResult.TotalCount += len(result.Listens)
|
||||
for _, listen := range result.Listens {
|
||||
if listen.ListenedAt.Unix() > importResult.LastTimestamp.Unix() {
|
||||
importResult.LastTimestamp = listen.ListenedAt
|
||||
}
|
||||
importResult.ImportCount += 1
|
||||
fmt.Printf("🎶 %v: \"%v\" by %v (%v)\n",
|
||||
listen.ListenedAt, listen.TrackName, listen.ArtistName(), listen.RecordingMbid)
|
||||
}
|
||||
result.ImportCount += 1
|
||||
fmt.Printf("🎶 %v: \"%v\" by %v (%v)\n",
|
||||
listen.ListenedAt, listen.TrackName, listen.ArtistName(), listen.RecordingMbid)
|
||||
}
|
||||
return result, nil
|
||||
return importResult, nil
|
||||
}
|
||||
|
||||
func (b DumpBackend) ImportLoves(loves []models.Love, oldestTimestamp time.Time) (models.ImportResult, error) {
|
||||
result := models.ImportResult{
|
||||
TotalCount: len(loves),
|
||||
func (b DumpBackend) ImportLoves(results chan models.LovesResult, oldestTimestamp time.Time) (models.ImportResult, error) {
|
||||
importResult := models.ImportResult{
|
||||
TotalCount: 0,
|
||||
ImportCount: 0,
|
||||
LastTimestamp: oldestTimestamp,
|
||||
}
|
||||
for _, love := range loves {
|
||||
if love.Created.Unix() > result.LastTimestamp.Unix() {
|
||||
result.LastTimestamp = love.Created
|
||||
for result := range results {
|
||||
if result.Error != nil {
|
||||
return importResult, result.Error
|
||||
}
|
||||
|
||||
importResult.TotalCount += len(result.Loves)
|
||||
for _, love := range result.Loves {
|
||||
if love.Created.Unix() > importResult.LastTimestamp.Unix() {
|
||||
importResult.LastTimestamp = love.Created
|
||||
}
|
||||
importResult.ImportCount += 1
|
||||
fmt.Printf("❤️ %v: \"%v\" by %v (%v)\n",
|
||||
love.Created, love.TrackName, love.ArtistName(), love.RecordingMbid)
|
||||
}
|
||||
result.ImportCount += 1
|
||||
fmt.Printf("❤️ %v: \"%v\" by %v (%v)\n",
|
||||
love.Created, love.TrackName, love.ArtistName(), love.RecordingMbid)
|
||||
}
|
||||
return result, nil
|
||||
return importResult, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue