Skip to content

Commit

Permalink
Add skipped stats
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonreinke committed Nov 19, 2023
1 parent fd788ba commit bacb0a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
5 changes: 3 additions & 2 deletions downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func (d *Downloader) createImage(item *LibraryItem, filePath string) error {
})
} else {
log.Printf("Skipping '%v' [saved as '%v']", item.Filename, item.UsedFileName)
d.stats.UpdateStatsSkipped(1)
}
return nil
}
Expand Down Expand Up @@ -331,11 +332,11 @@ func (d *Downloader) DownloadAll(svc *photoslibrary.Service) error {
}

if hasMore {
log.Printf("Processed: %v, Downloaded: %v, Errors: %v, Total Size: %v", d.stats.Total, d.stats.Downloaded, d.stats.Errors, humanize.Bytes(d.stats.TotalSize))
log.Printf("Processed: %v, Downloaded: %v, Skipped: %v, Errors: %v, Total Size: %v", d.stats.Total, d.stats.Downloaded, d.stats.Skipped, d.stats.Errors, humanize.Bytes(d.stats.TotalSize))
time.Sleep(sleepTime)
}
}

log.Printf("Finished: %v, Downloaded: %v, Errors: %v, Total Size: %v", d.stats.Total, d.stats.Downloaded, d.stats.Errors, humanize.Bytes(d.stats.TotalSize))
log.Printf("Finished: %v, Downloaded: %v, Skipped: %v, Errors: %v, Total Size: %v", d.stats.Total, d.stats.Downloaded, d.stats.Skipped, d.stats.Errors, humanize.Bytes(d.stats.TotalSize))
return nil
}
23 changes: 16 additions & 7 deletions downloader/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ import (

// Stats TODO
type Stats struct {
Total int
Errors int
TotalSize uint64
Total int
Errors int
TotalSize uint64
Downloaded int
Skipped int

mutex sync.Mutex
}

// UpdateStatsTotal TODO
// UpdateStatsTotal increment the total items
func (s *Stats) UpdateStatsTotal(total int) {
s.mutex.Lock()
defer s.mutex.Unlock()

s.Total += total
}

// UpdateStatsDownloaded TODO
// UpdateStatsDownloaded increment the downloaded items and size of items
func (s *Stats) UpdateStatsDownloaded(totalSize uint64, downloaded int) {
s.mutex.Lock()
defer s.mutex.Unlock()
Expand All @@ -31,10 +32,18 @@ func (s *Stats) UpdateStatsDownloaded(totalSize uint64, downloaded int) {
s.Downloaded += downloaded
}

// UpdateStatsError TODO
// UpdateStatsError increment the items that produced errors
func (s *Stats) UpdateStatsError(errors int) {
s.mutex.Lock()
defer s.mutex.Unlock()

s.Errors += errors
}
}

// UpdateStatsError increment the skipped items
func (s *Stats) UpdateStatsSkipped(skipped int) {
s.mutex.Lock()
defer s.mutex.Unlock()

s.Skipped += skipped
}

0 comments on commit bacb0a0

Please sign in to comment.