Add a backoff timeout to checking diskspace and logging about it

This commit is contained in:
Tony Blyler 2016-07-28 22:11:22 -04:00
parent 5cb62347e7
commit 588f0fb89b
No known key found for this signature in database
GPG key ID: 25C9D3A655D1A65C

View file

@ -21,6 +21,12 @@ import (
"time" "time"
) )
const (
// DefaultDiskSpaceBackoff denotes how long to wait before checking
// that the diskspace threshold is not longer being exceeded
DefaultDiskSpaceBackoff = time.Second * 30
)
// Config defines the settings for watching, uploading, and downloading // Config defines the settings for watching, uploading, and downloading
type Config struct { type Config struct {
Rtorrent struct { Rtorrent struct {
@ -467,6 +473,7 @@ func (q *Queue) Run(stop <-chan bool) {
var err error var err error
finished := false finished := false
lastUpdateTime := time.Time{} lastUpdateTime := time.Time{}
diskSpaceBackOff := time.Now()
downloadedHashes := make(chan string, q.config.ConcurrentDownloads) downloadedHashes := make(chan string, q.config.ConcurrentDownloads)
downloadsRunning := make(map[string]downloadInfo) downloadsRunning := make(map[string]downloadInfo)
for { for {
@ -569,7 +576,7 @@ func (q *Queue) Run(stop <-chan bool) {
} }
} }
if uint(len(downloadsRunning)) < q.config.ConcurrentDownloads { if uint(len(downloadsRunning)) < q.config.ConcurrentDownloads && (!q.config.CheckDiskSpace || diskSpaceBackOff.Before(time.Now())) {
for _, torrent := range q.getFinishedTorrents() { for _, torrent := range q.getFinishedTorrents() {
if _, exists := downloadsRunning[torrent.Hash]; exists { if _, exists := downloadsRunning[torrent.Hash]; exists {
continue continue
@ -611,6 +618,7 @@ func (q *Queue) Run(stop <-chan bool) {
continue continue
} }
diskSpaceBackOff = time.Now().Add(DefaultDiskSpaceBackoff)
q.logger.Printf("Not downloading '%s' (%s) not enough disk space, only %d bytes free on '%s'", torrent.Name, torrentFilePath, fsStat.Free, path) q.logger.Printf("Not downloading '%s' (%s) not enough disk space, only %d bytes free on '%s'", torrent.Name, torrentFilePath, fsStat.Free, path)
skip = true skip = true
break break
@ -619,6 +627,7 @@ func (q *Queue) Run(stop <-chan bool) {
continue continue
} }
diskSpaceBackOff = time.Now().Add(DefaultDiskSpaceBackoff)
q.logger.Printf("Not downloading '%s' (%s) minimum disk space (%d) reached on '%s'", torrent.Name, torrentFilePath, q.config.MinDiskSpace, path) q.logger.Printf("Not downloading '%s' (%s) minimum disk space (%d) reached on '%s'", torrent.Name, torrentFilePath, q.config.MinDiskSpace, path)
skip = true skip = true
break break