fix memory leak

fix missing ptr dereference
add single-run startup param
stop counting channels that aren't actually considered in the sync process
This commit is contained in:
Niko Storni 2018-08-21 13:17:52 -04:00
parent 51e19e097c
commit cfa33d59bb
2 changed files with 12 additions and 6 deletions

View file

@ -7,10 +7,9 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
"strings"
"time"
"syscall" "syscall"
"time"
"github.com/lbryio/lbry.go/errors" "github.com/lbryio/lbry.go/errors"
"github.com/lbryio/lbry.go/null" "github.com/lbryio/lbry.go/null"
@ -44,6 +43,7 @@ type SyncManager struct {
AwsS3Secret string AwsS3Secret string
AwsS3Region string AwsS3Region string
AwsS3Bucket string AwsS3Bucket string
SingleRun bool
} }
const ( const (
@ -270,6 +270,7 @@ func (s SyncManager) Start() error {
time.Sleep(5 * time.Minute) time.Sleep(5 * time.Minute)
} }
for i, sync := range syncs { for i, sync := range syncs {
shouldNotCount := false
SendInfoToSlack("Syncing %s (%s) to LBRY! (iteration %d/%d - total session iterations: %d)", sync.LbryChannelName, sync.YoutubeChannelID, i+1, len(syncs), syncCount+1) SendInfoToSlack("Syncing %s (%s) to LBRY! (iteration %d/%d - total session iterations: %d)", sync.LbryChannelName, sync.YoutubeChannelID, i+1, len(syncs), syncCount+1)
err := sync.FullCycle() err := sync.FullCycle()
if err != nil { if err != nil {
@ -278,21 +279,25 @@ func (s SyncManager) Start() error {
"WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR", "WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR",
"NotEnoughFunds", "NotEnoughFunds",
"no space left on device", "no space left on device",
"failure uploading wallet",
} }
if util.SubstringInSlice(err.Error(), fatalErrors) { if util.SubstringInSlice(err.Error(), fatalErrors) {
return errors.Prefix("@Nikooo777 this requires manual intervention! Exiting...", err) return errors.Prefix("@Nikooo777 this requires manual intervention! Exiting...", err)
} }
SendInfoToSlack("A non fatal error was reported by the sync process. %s\nContinuing...", err.Error()) SendInfoToSlack("A non fatal error was reported by the sync process. %s\nContinuing...", err.Error())
shouldNotCount = strings.Contains(err.Error(), "this youtube channel is being managed by another server")
} }
SendInfoToSlack("Syncing %s (%s) reached an end. (Iteration %d/%d - total session iterations: %d))", sync.LbryChannelName, sync.YoutubeChannelID, i+1, len(syncs), syncCount+1) SendInfoToSlack("Syncing %s (%s) reached an end. (Iteration %d/%d - total session iterations: %d))", sync.LbryChannelName, sync.YoutubeChannelID, i+1, len(syncs), syncCount+1)
syncCount++ if !shouldNotCount {
syncCount++
}
if sync.IsInterrupted() || (s.Limit != 0 && syncCount >= s.Limit) { if sync.IsInterrupted() || (s.Limit != 0 && syncCount >= s.Limit) {
shouldInterruptLoop = true shouldInterruptLoop = true
break break
} }
} }
if shouldInterruptLoop { if shouldInterruptLoop || s.SingleRun {
break break
} }
} }

View file

@ -230,6 +230,7 @@ func (s *Sync) FullCycle() (e error) {
s.queue = make(chan video) s.queue = make(chan video)
interruptChan := make(chan os.Signal, 1) interruptChan := make(chan os.Signal, 1)
signal.Notify(interruptChan, os.Interrupt, syscall.SIGTERM) signal.Notify(interruptChan, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(interruptChan)
go func() { go func() {
<-interruptChan <-interruptChan
log.Println("Got interrupt signal, shutting down (if publishing, will shut down after current publish)") log.Println("Got interrupt signal, shutting down (if publishing, will shut down after current publish)")
@ -345,7 +346,7 @@ func (s *Sync) stopAndUploadWallet(e *error) {
e = &err e = &err
return return
} else { } else {
*e = errors.Prefix("failure uploading wallet: ", e) *e = errors.Prefix("failure uploading wallet: ", *e)
} }
} }
} }